mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	list out the items
This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
			
		||||
apply plugin: 'com.android.application'
 | 
			
		||||
apply plugin: 'android-apt'
 | 
			
		||||
 | 
			
		||||
android {
 | 
			
		||||
    compileSdkVersion 23
 | 
			
		||||
@@ -23,4 +24,7 @@ dependencies {
 | 
			
		||||
    compile fileTree(dir: 'libs', include: ['*.jar'])
 | 
			
		||||
    testCompile 'junit:junit:4.12'
 | 
			
		||||
    compile 'com.android.support:appcompat-v7:23.4.0'
 | 
			
		||||
    compile 'com.jakewharton:butterknife:8.0.1'
 | 
			
		||||
 | 
			
		||||
    apt 'com.jakewharton:butterknife-compiler:8.0.1'
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,6 @@
 | 
			
		||||
        android:allowBackup="true"
 | 
			
		||||
        android:icon="@mipmap/ic_launcher"
 | 
			
		||||
        android:label="@string/app_name"
 | 
			
		||||
        android:supportsRtl="true"
 | 
			
		||||
        android:theme="@style/AppTheme">
 | 
			
		||||
        <activity android:name=".activities.MainActivity">
 | 
			
		||||
            <intent-filter>
 | 
			
		||||
 
 | 
			
		||||
@@ -6,9 +6,13 @@ 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.R;
 | 
			
		||||
import com.simplemobiletools.filemanager.Utils;
 | 
			
		||||
import com.simplemobiletools.filemanager.adapters.ItemsAdapter;
 | 
			
		||||
import com.simplemobiletools.filemanager.models.FileDirItem;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
@@ -16,13 +20,19 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class MainActivity extends AppCompatActivity {
 | 
			
		||||
import butterknife.BindView;
 | 
			
		||||
import butterknife.ButterKnife;
 | 
			
		||||
 | 
			
		||||
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
 | 
			
		||||
    @BindView(R.id.items_list) ListView mListView;
 | 
			
		||||
 | 
			
		||||
    private static final int STORAGE_PERMISSION = 1;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        setContentView(R.layout.activity_main);
 | 
			
		||||
        ButterKnife.bind(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -42,6 +52,10 @@ public class MainActivity extends AppCompatActivity {
 | 
			
		||||
    private void initializeFileManager() {
 | 
			
		||||
        List<FileDirItem> items = getItems();
 | 
			
		||||
        Collections.sort(items);
 | 
			
		||||
 | 
			
		||||
        final ItemsAdapter adapter = new ItemsAdapter(this, items);
 | 
			
		||||
        mListView.setAdapter(adapter);
 | 
			
		||||
        mListView.setOnItemClickListener(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -70,4 +84,9 @@ public class MainActivity extends AppCompatActivity {
 | 
			
		||||
        }
 | 
			
		||||
        return items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,72 @@
 | 
			
		||||
package com.simplemobiletools.filemanager.adapters;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.view.LayoutInflater;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.view.ViewGroup;
 | 
			
		||||
import android.widget.BaseAdapter;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
 | 
			
		||||
import com.simplemobiletools.filemanager.R;
 | 
			
		||||
import com.simplemobiletools.filemanager.models.FileDirItem;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import butterknife.BindView;
 | 
			
		||||
import butterknife.ButterKnife;
 | 
			
		||||
 | 
			
		||||
public class ItemsAdapter extends BaseAdapter {
 | 
			
		||||
    private final List<FileDirItem> mItems;
 | 
			
		||||
    private final LayoutInflater mInflater;
 | 
			
		||||
 | 
			
		||||
    public ItemsAdapter(Context context, List<FileDirItem> items) {
 | 
			
		||||
        mItems = items;
 | 
			
		||||
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public View getView(int position, View convertView, ViewGroup parent) {
 | 
			
		||||
        ViewHolder viewHolder;
 | 
			
		||||
        if (convertView == null) {
 | 
			
		||||
            convertView = mInflater.inflate(R.layout.list_item, parent, false);
 | 
			
		||||
            viewHolder = new ViewHolder(convertView);
 | 
			
		||||
            convertView.setTag(viewHolder);
 | 
			
		||||
        } else {
 | 
			
		||||
            viewHolder = (ViewHolder) convertView.getTag();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final FileDirItem item = mItems.get(position);
 | 
			
		||||
        viewHolder.name.setText(item.getName());
 | 
			
		||||
 | 
			
		||||
        return convertView;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getCount() {
 | 
			
		||||
        return mItems.size();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Object getItem(int position) {
 | 
			
		||||
        return mItems.get(position);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public long getItemId(int position) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updateItems(List<FileDirItem> newItems) {
 | 
			
		||||
        mItems.clear();
 | 
			
		||||
        mItems.addAll(newItems);
 | 
			
		||||
        notifyDataSetChanged();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static class ViewHolder {
 | 
			
		||||
        @BindView(R.id.item_name) TextView name;
 | 
			
		||||
 | 
			
		||||
        public ViewHolder(View view) {
 | 
			
		||||
            ButterKnife.bind(this, view);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,8 +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"
 | 
			
		||||
    android:padding="@dimen/activity_margin">
 | 
			
		||||
    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>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								app/src/main/res/layout/list_item.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								app/src/main/res/layout/list_item.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<RelativeLayout
 | 
			
		||||
    android:id="@+id/item_holder"
 | 
			
		||||
    xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    android:layout_width="match_parent"
 | 
			
		||||
    android:layout_height="wrap_content"
 | 
			
		||||
    android:paddingBottom="@dimen/activity_margin"
 | 
			
		||||
    android:paddingRight="@dimen/activity_margin"
 | 
			
		||||
    android:paddingTop="@dimen/activity_margin">
 | 
			
		||||
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/item_name"
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="wrap_content"/>
 | 
			
		||||
 | 
			
		||||
</RelativeLayout>
 | 
			
		||||
@@ -6,6 +6,7 @@ buildscript {
 | 
			
		||||
    }
 | 
			
		||||
    dependencies {
 | 
			
		||||
        classpath 'com.android.tools.build:gradle:2.1.2'
 | 
			
		||||
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
 | 
			
		||||
 | 
			
		||||
        // NOTE: Do not place your application dependencies here; they belong
 | 
			
		||||
        // in the individual module build.gradle files
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user