diff --git a/build.gradle b/build.gradle index 25708c2..b098f46 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,14 @@ ext { - supportLibraryVersion = '28.0.0' - - minSdkVersion = 17 - targetSdkVersion = 28 - versionCode = 8 - versionName = "0.2.3" + minSdkVersion = 17 + targetSdkVersion = 28 + versionCode = 9 + versionName = "0.2.4" } buildscript { repositories { jcenter() - google() + google() } dependencies { classpath 'com.android.tools.build:gradle:3.3.1' @@ -20,7 +18,7 @@ buildscript { allprojects { repositories { jcenter() - google() + google() maven { url 'https://jitpack.io' } } } diff --git a/demo/build.gradle b/demo/build.gradle index d241dde..cd07c8e 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -20,7 +20,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.android.support:appcompat-v7:$supportLibraryVersion" - implementation "com.android.support:design:$supportLibraryVersion" + implementation "androidx.appcompat:appcompat:1.0.2" + implementation "com.google.android.material:material:1.1.0-alpha04" implementation project(':library') } diff --git a/demo/src/main/java/moe/feng/common/view/breadcrumbs/App.java b/demo/src/main/java/moe/feng/common/view/breadcrumbs/App.java index fa4255d..f98258a 100644 --- a/demo/src/main/java/moe/feng/common/view/breadcrumbs/App.java +++ b/demo/src/main/java/moe/feng/common/view/breadcrumbs/App.java @@ -1,10 +1,10 @@ package moe.feng.common.view.breadcrumbs; import android.app.Application; -import android.support.v7.app.AppCompatDelegate; -public class App extends Application -{ +import androidx.appcompat.app.AppCompatDelegate; + +public class App extends Application { @Override public void onCreate() { super.onCreate(); diff --git a/demo/src/main/java/moe/feng/common/view/breadcrumbs/FileManagerAdapter.java b/demo/src/main/java/moe/feng/common/view/breadcrumbs/FileManagerAdapter.java index 2498a9d..73fecd2 100644 --- a/demo/src/main/java/moe/feng/common/view/breadcrumbs/FileManagerAdapter.java +++ b/demo/src/main/java/moe/feng/common/view/breadcrumbs/FileManagerAdapter.java @@ -1,11 +1,12 @@ package moe.feng.common.view.breadcrumbs; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; + +import androidx.recyclerview.widget.RecyclerView; import moe.feng.common.view.breadcrumbs.model.FileList; import moe.feng.common.view.breadcrumbs.demo.R; diff --git a/demo/src/main/java/moe/feng/common/view/breadcrumbs/MainActivity.java b/demo/src/main/java/moe/feng/common/view/breadcrumbs/MainActivity.java index 55211ff..1ca1458 100644 --- a/demo/src/main/java/moe/feng/common/view/breadcrumbs/MainActivity.java +++ b/demo/src/main/java/moe/feng/common/view/breadcrumbs/MainActivity.java @@ -4,18 +4,19 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; -import android.support.design.widget.CoordinatorLayout; -import android.support.design.widget.Snackbar; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.view.View; +import com.google.android.material.snackbar.Snackbar; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import moe.feng.common.view.breadcrumbs.demo.R; import moe.feng.common.view.breadcrumbs.model.BreadcrumbItem; diff --git a/demo/src/main/java/moe/feng/common/view/breadcrumbs/SimpleFileManagerActivity.java b/demo/src/main/java/moe/feng/common/view/breadcrumbs/SimpleFileManagerActivity.java index 5c88eeb..0221b9a 100644 --- a/demo/src/main/java/moe/feng/common/view/breadcrumbs/SimpleFileManagerActivity.java +++ b/demo/src/main/java/moe/feng/common/view/breadcrumbs/SimpleFileManagerActivity.java @@ -3,134 +3,137 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; -import android.support.design.widget.Snackbar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; + +import com.google.android.material.snackbar.Snackbar; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.RecyclerView; +import moe.feng.common.view.breadcrumbs.demo.R; import moe.feng.common.view.breadcrumbs.model.BreadcrumbItem; import moe.feng.common.view.breadcrumbs.model.FileList; -import moe.feng.common.view.breadcrumbs.demo.R; public class SimpleFileManagerActivity extends AppCompatActivity { - private BreadcrumbsView mBreadcrumbsView; - private RecyclerView mRecyclerView; - private FileManagerAdapter mAdapter; - - private String currentLocation; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_simple_file_manager); - Toolbar toolbar = findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - mRecyclerView = findViewById(R.id.recycler_view); - mBreadcrumbsView = findViewById(R.id.breadcrumbs_view); - - mAdapter = new FileManagerAdapter(); - mRecyclerView.setAdapter(mAdapter); - mAdapter.setCallback(new FileManagerAdapter.Callback() { - @Override - public void onItemClick(FileList.FileWrapper file) { - if (file.isDirectory()) { - BreadcrumbItem breadcrumbItem = new BreadcrumbItem(mAdapter.getFileList().getDirectoriesString()); - breadcrumbItem.setSelectedItem(file.toString()); - currentLocation = getCurrentPath() + "/" + file.toString(); - new LoadTask(breadcrumbItem).execute(currentLocation); - } else if (file.isFile()) { - // Nothing happen lol - } - } - }); - - mBreadcrumbsView.setCallback(new DefaultBreadcrumbsCallback() { - @Override - public void onNavigateBack(BreadcrumbItem item, int position) { - currentLocation = getPath(position); - new LoadTask().execute(currentLocation); - } - - @Override - public void onNavigateNewLocation(BreadcrumbItem newItem, int changedPosition) { - currentLocation = getPath(changedPosition - 1) + "/" + newItem.getSelectedItem(); - new LoadTask().execute(currentLocation); - } - }); - - if (savedInstanceState == null) { - mBreadcrumbsView.addItem(BreadcrumbItem.createSimpleItem("External Storage")); - currentLocation = getCurrentPath(); - new LoadTask().execute(currentLocation); - } - } - - @Override - public void onRestoreInstanceState(Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - currentLocation = getCurrentPath(); - new LoadTask().execute(currentLocation); - } - - private String getCurrentPath() { - return getPath(-1); - } - - private String getPath(int depth) { - if (depth == -1) depth = mBreadcrumbsView.getItems().size() - 1; - StringBuffer sb = new StringBuffer(Environment.getExternalStorageDirectory().getAbsolutePath()); - for (int i = 1; i <= depth; i++) { - sb.append("/").append(mBreadcrumbsView.getItems().get(i).getSelectedItem()); - } - return sb.toString(); - } - - @Override - public void onBackPressed() { - if (mBreadcrumbsView.getItems().size() > 1) { - mBreadcrumbsView.removeLastItem(); - currentLocation = getCurrentPath(); - new LoadTask().execute(currentLocation); - } else { - super.onBackPressed(); - } - } - - private class LoadTask extends AsyncTask { - - private BreadcrumbItem nextItem; - - LoadTask() {} - - LoadTask(BreadcrumbItem nextItem) { - this.nextItem = nextItem; - } - - @Override - protected FileList doInBackground(String... path) { - try { - return FileList.newInstance(path[0]); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - @Override - protected void onPostExecute(FileList list) { - if (list != null) { - mAdapter.setFileList(list); - mAdapter.notifyDataSetChanged(); - if (nextItem != null) { - mBreadcrumbsView.addItem(nextItem); - } - } else if (nextItem != null) { - Snackbar.make(findViewById(R.id.coordinator_layout), "Something wrong", Snackbar.LENGTH_SHORT) - .show(); - } - } - - } + private BreadcrumbsView mBreadcrumbsView; + private RecyclerView mRecyclerView; + private FileManagerAdapter mAdapter; + + private String currentLocation; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_simple_file_manager); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + mRecyclerView = findViewById(R.id.recycler_view); + mBreadcrumbsView = findViewById(R.id.breadcrumbs_view); + + mAdapter = new FileManagerAdapter(); + mRecyclerView.setAdapter(mAdapter); + mAdapter.setCallback(new FileManagerAdapter.Callback() { + @Override + public void onItemClick(FileList.FileWrapper file) { + if (file.isDirectory()) { + BreadcrumbItem breadcrumbItem = new BreadcrumbItem(mAdapter.getFileList().getDirectoriesString()); + breadcrumbItem.setSelectedItem(file.toString()); + currentLocation = getCurrentPath() + "/" + file.toString(); + new LoadTask(breadcrumbItem).execute(currentLocation); + } else if (file.isFile()) { + // Nothing happen lol + } + } + }); + + mBreadcrumbsView.setCallback(new DefaultBreadcrumbsCallback() { + @Override + public void onNavigateBack(BreadcrumbItem item, int position) { + currentLocation = getPath(position); + new LoadTask().execute(currentLocation); + } + + @Override + public void onNavigateNewLocation(BreadcrumbItem newItem, int changedPosition) { + currentLocation = getPath(changedPosition - 1) + "/" + newItem.getSelectedItem(); + new LoadTask().execute(currentLocation); + } + }); + + if (savedInstanceState == null) { + mBreadcrumbsView.addItem(BreadcrumbItem.createSimpleItem("External Storage")); + currentLocation = getCurrentPath(); + new LoadTask().execute(currentLocation); + } + } + + @Override + public void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + currentLocation = getCurrentPath(); + new LoadTask().execute(currentLocation); + } + + private String getCurrentPath() { + return getPath(-1); + } + + private String getPath(int depth) { + if (depth == -1) depth = mBreadcrumbsView.getItems().size() - 1; + StringBuffer sb = new StringBuffer(Environment.getExternalStorageDirectory().getAbsolutePath()); + for (int i = 1; i <= depth; i++) { + sb.append("/").append(mBreadcrumbsView.getItems().get(i).getSelectedItem()); + } + return sb.toString(); + } + + @Override + public void onBackPressed() { + if (mBreadcrumbsView.getItems().size() > 1) { + mBreadcrumbsView.removeLastItem(); + currentLocation = getCurrentPath(); + new LoadTask().execute(currentLocation); + } else { + super.onBackPressed(); + } + } + + private class LoadTask extends AsyncTask { + + private BreadcrumbItem nextItem; + + LoadTask() { + } + + LoadTask(BreadcrumbItem nextItem) { + this.nextItem = nextItem; + } + + @Override + protected FileList doInBackground(String... path) { + try { + return FileList.newInstance(path[0]); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(FileList list) { + if (list != null) { + mAdapter.setFileList(list); + mAdapter.notifyDataSetChanged(); + if (nextItem != null) { + mBreadcrumbsView.addItem(nextItem); + } + } else if (nextItem != null) { + Snackbar.make(findViewById(R.id.coordinator_layout), "Something wrong", Snackbar.LENGTH_SHORT) + .show(); + } + } + + } } diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml index 19770c1..e718b94 100644 --- a/demo/src/main/res/layout/activity_main.xml +++ b/demo/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - - - + - + diff --git a/demo/src/main/res/layout/activity_simple_file_manager.xml b/demo/src/main/res/layout/activity_simple_file_manager.xml index 0feaed1..a66c302 100644 --- a/demo/src/main/res/layout/activity_simple_file_manager.xml +++ b/demo/src/main/res/layout/activity_simple_file_manager.xml @@ -1,40 +1,39 @@ - + - + - + - + - + - + - + diff --git a/demo/src/main/res/layout/content_main.xml b/demo/src/main/res/layout/content_main.xml index 34c278b..cb08279 100644 --- a/demo/src/main/res/layout/content_main.xml +++ b/demo/src/main/res/layout/content_main.xml @@ -1,30 +1,29 @@ - + -