From 4b8eaf2e2d466f168e481d673ada757c3645b171 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 13 Jul 2016 11:32:23 +0200 Subject: [PATCH] list out the items --- app/build.gradle | 4 ++ app/src/main/AndroidManifest.xml | 1 - .../filemanager/activities/MainActivity.java | 21 +++++- .../filemanager/adapters/ItemsAdapter.java | 72 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 10 ++- app/src/main/res/layout/list_item.xml | 16 +++++ build.gradle | 1 + 7 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java create mode 100644 app/src/main/res/layout/list_item.xml diff --git a/app/build.gradle b/app/build.gradle index 7097f1bd..c936bf78 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3ae46d84..7be1c9ff 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,7 +8,6 @@ android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:supportsRtl="true" android:theme="@style/AppTheme"> 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 f997d906..33c136ab 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java @@ -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 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) { + + } } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java b/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java new file mode 100644 index 00000000..5d9e393a --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java @@ -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 mItems; + private final LayoutInflater mInflater; + + public ItemsAdapter(Context context, List 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 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); + } + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 63c6e801..3dfd2f5b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,8 +1,14 @@ + android:layout_height="match_parent"> + + diff --git a/app/src/main/res/layout/list_item.xml b/app/src/main/res/layout/list_item.xml new file mode 100644 index 00000000..cd8b3c0b --- /dev/null +++ b/app/src/main/res/layout/list_item.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/build.gradle b/build.gradle index aff4f415..165abe55 100644 --- a/build.gradle +++ b/build.gradle @@ -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