move the list to a fragment
This commit is contained in:
parent
aadcf70853
commit
2ec9ff6973
|
@ -0,0 +1,5 @@
|
|||
package com.simplemobiletools.filemanager;
|
||||
|
||||
public class Constants {
|
||||
public static final String PATH = "path";
|
||||
}
|
|
@ -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<FileDirItem> 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<FileDirItem> getItems() {
|
||||
final List<FileDirItem> 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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<FileDirItem> items = getItems(path);
|
||||
Collections.sort(items);
|
||||
|
||||
final ItemsAdapter adapter = new ItemsAdapter(getContext(), items);
|
||||
mListView.setAdapter(adapter);
|
||||
mListView.setOnItemClickListener(this);
|
||||
}
|
||||
|
||||
private List<FileDirItem> getItems(String path) {
|
||||
final List<FileDirItem> 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) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,14 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
android:id="@+id/items_holder"
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_holder"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/items_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/activity_margin"/>
|
||||
|
||||
</RelativeLayout>
|
||||
android:layout_height="match_parent"/>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
android:id="@+id/items_holder"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/items_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/activity_margin"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in New Issue