1
+ package org .opendroidphp .app .ui ;
2
+
3
+ import android .app .Activity ;
4
+ import android .os .Bundle ;
5
+ import android .support .v4 .app .DialogFragment ;
6
+ import android .view .LayoutInflater ;
7
+ import android .view .View ;
8
+ import android .view .ViewGroup ;
9
+ import android .widget .AdapterView ;
10
+ import android .widget .Button ;
11
+ import android .widget .ListView ;
12
+
13
+ import com .actionbarsherlock .app .SherlockFragment ;
14
+
15
+ import org .opendroidphp .R ;
16
+ import org .opendroidphp .app .adapter .FileListAdapter ;
17
+ import org .opendroidphp .app .common .parser .Finder ;
18
+ import org .opendroidphp .app .fragments .dialogs .EditorDialogFragment ;
19
+ import org .opendroidphp .app .listeners .OnInflationListener ;
20
+ import org .opendroidphp .app .tasks .FileFinderTask ;
21
+
22
+ import java .io .File ;
23
+ import java .util .HashMap ;
24
+
25
+ public class FileFragment extends SherlockFragment implements AdapterView .OnItemClickListener , View .OnClickListener {
26
+
27
+
28
+ private static OnInflationListener sInflateCallback ;
29
+ protected HashMap <Integer , Finder > fileMap ;
30
+ private ListView mVirtualView ;
31
+ private FileListAdapter mAdapter ;
32
+
33
+ @ Override
34
+ public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
35
+ final View rootView = inflater .inflate (R .layout .fragment_file , container , false );
36
+ final FileFinderTask task = FileFinderTask .createFor (getSherlockActivity (), new FileFinderTask .FileEvent () {
37
+
38
+ @ Override
39
+ public void onReceived (HashMap <Integer , Finder > file ) {
40
+ fileMap = file ;
41
+ prepareView (rootView );
42
+ }
43
+
44
+ @ Override
45
+ public void onError (Exception e ) {
46
+ e .printStackTrace ();
47
+ }
48
+ });
49
+ task .execute ();
50
+ return rootView ;
51
+ }
52
+
53
+ @ Override
54
+ public void onAttach (Activity activity ) {
55
+ super .onAttach (activity );
56
+ try {
57
+ sInflateCallback = (OnInflationListener ) activity ;
58
+ } catch (ClassCastException e ) {
59
+ throw new ClassCastException (activity .toString () + "must implement OnInflateViewListener" );
60
+ }
61
+ }
62
+
63
+ @ Override
64
+ public void onClick (View view ) {
65
+ if (view instanceof Button ) {
66
+ sInflateCallback .setOnFragmentReceived (new ManageFileFragment ());
67
+ }
68
+ }
69
+
70
+ @ Override
71
+ public void onItemClick (AdapterView <?> adapterView , View view , int i , long l ) {
72
+ String filePath = fileMap .get (i ).find ("file_location" );
73
+ File file = new File (filePath );
74
+ DialogFragment fragment = EditorDialogFragment .create (file );
75
+ fragment .show (getFragmentManager (), getClass ().getSimpleName ());
76
+ }
77
+
78
+ protected void prepareView (View view ) {
79
+ mVirtualView = (ListView ) view .findViewById (R .id .file_list );
80
+ mAdapter = new FileListAdapter (getSherlockActivity (), fileMap );
81
+ mVirtualView .setAdapter (mAdapter );
82
+ mVirtualView .setOnItemClickListener (this );
83
+ // Button btnCreate = (Button) view.findViewById(R.id.btn_create_host);
84
+ // btnCreate.setOnClickListener(this);
85
+ }
86
+ }
0 commit comments