diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Constants.java b/app/src/main/java/com/simplemobiletools/filemanager/Constants.java new file mode 100644 index 00000000..e2dcd969 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/filemanager/Constants.java @@ -0,0 +1,5 @@ +package com.simplemobiletools.filemanager; + +public class Constants { + public static final String PATH = "path"; +} diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java index 33c136ab..b471a9be 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java @@ -6,26 +6,15 @@ import android.os.Bundle; import android.os.Environment; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; +import com.simplemobiletools.filemanager.Constants; import com.simplemobiletools.filemanager.R; import com.simplemobiletools.filemanager.Utils; -import com.simplemobiletools.filemanager.adapters.ItemsAdapter; -import com.simplemobiletools.filemanager.models.FileDirItem; +import com.simplemobiletools.filemanager.fragments.ItemsFragment; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import butterknife.BindView; import butterknife.ButterKnife; -public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { - @BindView(R.id.items_list) ListView mListView; - +public class MainActivity extends AppCompatActivity { private static final int STORAGE_PERMISSION = 1; @Override @@ -50,12 +39,13 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte } private void initializeFileManager() { - List items = getItems(); - Collections.sort(items); + final Bundle bundle = new Bundle(); + final String path = Environment.getExternalStorageDirectory().toString(); + bundle.putString(Constants.PATH, path); - final ItemsAdapter adapter = new ItemsAdapter(this, items); - mListView.setAdapter(adapter); - mListView.setOnItemClickListener(this); + final ItemsFragment fragment = new ItemsFragment(); + fragment.setArguments(bundle); + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, fragment).commit(); } @Override @@ -71,22 +61,4 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte } } } - - private List getItems() { - final List items = new ArrayList<>(); - final String path = Environment.getExternalStorageDirectory().toString(); - final File root = new File(path); - File[] files = root.listFiles(); - for (File file : files) { - final String curPath = file.getAbsolutePath(); - final String curName = Utils.getFilename(curPath); - items.add(new FileDirItem(curPath, curName, file.isDirectory())); - } - return items; - } - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - - } } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java new file mode 100644 index 00000000..b8b76bbe --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -0,0 +1,65 @@ +package com.simplemobiletools.filemanager.fragments; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ListView; + +import com.simplemobiletools.filemanager.Constants; +import com.simplemobiletools.filemanager.R; +import com.simplemobiletools.filemanager.Utils; +import com.simplemobiletools.filemanager.adapters.ItemsAdapter; +import com.simplemobiletools.filemanager.models.FileDirItem; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class ItemsFragment extends android.support.v4.app.Fragment implements AdapterView.OnItemClickListener { + @BindView(R.id.items_list) ListView mListView; + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.items_fragment, container, false); + ButterKnife.bind(this, view); + return view; + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + final String path = getArguments().getString(Constants.PATH); + List items = getItems(path); + Collections.sort(items); + + final ItemsAdapter adapter = new ItemsAdapter(getContext(), items); + mListView.setAdapter(adapter); + mListView.setOnItemClickListener(this); + } + + private List getItems(String path) { + final List items = new ArrayList<>(); + final File root = new File(path); + File[] files = root.listFiles(); + for (File file : files) { + final String curPath = file.getAbsolutePath(); + final String curName = Utils.getFilename(curPath); + items.add(new FileDirItem(curPath, curName, file.isDirectory())); + } + return items; + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3dfd2f5b..a1407913 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,14 +1,6 @@ - - - - - + android:layout_height="match_parent"/> diff --git a/app/src/main/res/layout/items_fragment.xml b/app/src/main/res/layout/items_fragment.xml new file mode 100644 index 00000000..3dfd2f5b --- /dev/null +++ b/app/src/main/res/layout/items_fragment.xml @@ -0,0 +1,14 @@ + + + + + +