Skip to content

Commit

Permalink
Migrate to androidX
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed Mar 10, 2019
1 parent 481db06 commit 8799653
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 256 deletions.
14 changes: 6 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -20,7 +18,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
google()
maven { url 'https://jitpack.io' }
}
}
Expand Down
4 changes: 2 additions & 2 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
6 changes: 3 additions & 3 deletions demo/src/main/java/moe/feng/common/view/breadcrumbs/App.java
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BreadcrumbItem>() {
@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<String, Void, FileList> {

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<BreadcrumbItem>() {
@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<String, Void, FileList> {

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();
}
}

}

}
10 changes: 5 additions & 5 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator_layout"
Expand All @@ -8,13 +8,13 @@
android:fitsSystemWindows="true"
tools:context="moe.feng.common.view.breadcrumbs.MainActivity">

<android.support.design.widget.AppBarLayout
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
Expand All @@ -29,8 +29,8 @@
app:textColorUnSelected="@color/colorUnSelected"
app:textSizeCustom="12sp" />

</android.support.design.widget.AppBarLayout>
</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading

0 comments on commit 8799653

Please sign in to comment.