├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── koma
│ │ └── filemanager
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── koma
│ │ │ └── filemanager
│ │ │ ├── FileManagerApplication.java
│ │ │ ├── archive
│ │ │ ├── ArchiveActivity.java
│ │ │ ├── ArchiveAdapter.java
│ │ │ ├── ArchiveContract.java
│ │ │ ├── ArchiveFragment.java
│ │ │ └── ArchivePresenter.java
│ │ │ ├── audio
│ │ │ ├── AudioActivity.java
│ │ │ ├── AudioAdapter.java
│ │ │ ├── AudioConstract.java
│ │ │ ├── AudioFragment.java
│ │ │ ├── AudioPlayerActivity.java
│ │ │ └── AudioPresenter.java
│ │ │ ├── base
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseAdapter.java
│ │ │ ├── BaseFile.java
│ │ │ ├── BaseFragment.java
│ │ │ ├── BaseMenuActivity.java
│ │ │ ├── BasePresenter.java
│ │ │ ├── BaseSelectableAdapter.java
│ │ │ ├── BaseSwipeBackActivity.java
│ │ │ ├── BaseView.java
│ │ │ └── BaseViewHolder.java
│ │ │ ├── data
│ │ │ ├── FileDataSource.java
│ │ │ ├── FileRepository.java
│ │ │ ├── LocalDataSource.java
│ │ │ └── model
│ │ │ │ ├── ApkFile.java
│ │ │ │ ├── AudioFile.java
│ │ │ │ ├── Disk.java
│ │ │ │ ├── DocumentFile.java
│ │ │ │ ├── ImageFile.java
│ │ │ │ ├── VideoFile.java
│ │ │ │ └── ZipFile.java
│ │ │ ├── filecategory
│ │ │ ├── FileCategoryActivity.java
│ │ │ ├── FileCategoryAdapter.java
│ │ │ ├── FileCategoryContract.java
│ │ │ ├── FileCategoryFragment.java
│ │ │ └── FileCategoryPresenter.java
│ │ │ ├── fileview
│ │ │ ├── FileViewActivity.java
│ │ │ ├── FileViewAdapter.java
│ │ │ ├── FileViewContract.java
│ │ │ ├── FileViewFragment.java
│ │ │ └── FileViewPresenter.java
│ │ │ ├── helper
│ │ │ ├── ActionModeHelper.java
│ │ │ ├── FileCountHelper.java
│ │ │ ├── FileHelper.java
│ │ │ ├── FileSortHelper.java
│ │ │ ├── ImageLoder.java
│ │ │ ├── MeidaHelper.java
│ │ │ ├── RxBus.java
│ │ │ ├── SelectHelper.java
│ │ │ └── event
│ │ │ │ ├── SelectEvent.java
│ │ │ │ └── SortEvent.java
│ │ │ ├── image
│ │ │ ├── ImageActivity.java
│ │ │ ├── ImageAdapter.java
│ │ │ ├── ImageConstract.java
│ │ │ ├── ImageFragment.java
│ │ │ └── ImagePresenter.java
│ │ │ ├── main
│ │ │ ├── DiskAdapter.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MainContract.java
│ │ │ └── MainPresenter.java
│ │ │ ├── search
│ │ │ ├── SearchActivity.java
│ │ │ ├── SearchContract.java
│ │ │ ├── SearchFragment.java
│ │ │ └── SearchPresenter.java
│ │ │ ├── splash
│ │ │ └── SplashActivity.java
│ │ │ ├── util
│ │ │ ├── BlurUtils.java
│ │ │ ├── Constants.java
│ │ │ ├── FileCategoryUtils.java
│ │ │ ├── FileUtils.java
│ │ │ ├── LocaleUtils.java
│ │ │ ├── LogUtils.java
│ │ │ └── Utils.java
│ │ │ ├── video
│ │ │ ├── VideoActivity.java
│ │ │ ├── VideoContract.java
│ │ │ ├── VideoFragment.java
│ │ │ └── VideoPresenter.java
│ │ │ ├── volumeinfo
│ │ │ ├── VolumeInfoActivity.java
│ │ │ ├── VolumeInfoAdapter.java
│ │ │ ├── VolumeInfoContract.java
│ │ │ ├── VolumeInfoFragment.java
│ │ │ └── VolumeInfoPresenter.java
│ │ │ └── widget
│ │ │ ├── CategoryButton.java
│ │ │ ├── DividerItemDecoration.java
│ │ │ ├── FastScroller.java
│ │ │ ├── InputNameDialog.java
│ │ │ └── LoadingView.java
│ └── res
│ │ ├── drawable
│ │ ├── fast_scroller_bubble.xml
│ │ ├── fast_scroller_handle.xml
│ │ ├── ic_add.xml
│ │ ├── ic_back.xml
│ │ ├── ic_create_new_folder_black_24dp.xml
│ │ ├── ic_cut.xml
│ │ ├── ic_cut_grey_24dp.xml
│ │ ├── ic_cut_white_24dp.xml
│ │ ├── ic_delete.xml
│ │ ├── ic_delete_grey_24dp.xml
│ │ ├── ic_delete_white_24dp.xml
│ │ ├── ic_favorite.xml
│ │ ├── ic_filter_list.xml
│ │ ├── ic_menu_camera.xml
│ │ ├── ic_menu_gallery.xml
│ │ ├── ic_menu_manage.xml
│ │ ├── ic_menu_send.xml
│ │ ├── ic_menu_slideshow.xml
│ │ ├── ic_more_vert.xml
│ │ ├── ic_more_vert_grey_24dp.xml
│ │ ├── ic_more_vert_white_24dp.xml
│ │ ├── ic_search.xml
│ │ ├── ic_settings.xml
│ │ ├── ic_share.xml
│ │ ├── ic_share_grey_24dp.xml
│ │ ├── ic_share_white_24dp.xml
│ │ ├── ic_unfavorite.xml
│ │ ├── progress_bar.xml
│ │ └── side_nav_bar.xml
│ │ ├── layout
│ │ ├── action_mode_view.xml
│ │ ├── activity_main.xml
│ │ ├── app_bar_main.xml
│ │ ├── archive_item_view.xml
│ │ ├── category_button_layout.xml
│ │ ├── common_layout.xml
│ │ ├── content_main.xml
│ │ ├── divider_line.xml
│ │ ├── fast_scroller.xml
│ │ ├── fragment_volume_info.xml
│ │ ├── input_name_dialog_layout.xml
│ │ ├── item_disk.xml
│ │ ├── item_view.xml
│ │ ├── item_view_volume_info.xml
│ │ ├── library_fast_scroller_layout.xml
│ │ ├── loading_view.xml
│ │ ├── nav_header_main.xml
│ │ ├── recyclerview.xml
│ │ └── splashactivity_layout.xml
│ │ ├── menu
│ │ ├── activity_main_drawer.xml
│ │ ├── common_menu.xml
│ │ ├── main.xml
│ │ ├── menu_sort.xml
│ │ └── select_mode_menu.xml
│ │ ├── mipmap-xhdpi
│ │ ├── category_apk.png
│ │ ├── category_audio.png
│ │ ├── category_doc.png
│ │ ├── category_image.png
│ │ ├── category_video.png
│ │ ├── category_zip.png
│ │ ├── defaut_image.png
│ │ ├── empty_icon.png
│ │ ├── ic_dropdown.png
│ │ ├── ic_launcher.png
│ │ ├── ic_menu_share.png
│ │ ├── item_audio.png
│ │ ├── item_compress.png
│ │ ├── item_document.png
│ │ ├── item_folder.png
│ │ ├── item_ppt.png
│ │ ├── item_text.png
│ │ ├── item_video.png
│ │ └── item_xls.png
│ │ ├── mipmap-xxhdpi
│ │ ├── category_apk.png
│ │ ├── category_audio.png
│ │ ├── category_doc.png
│ │ ├── category_file_icon_video.png
│ │ ├── category_image.png
│ │ ├── category_zip.png
│ │ ├── ic_launcher.png
│ │ ├── item_app.png
│ │ ├── item_audio.png
│ │ ├── item_compress.png
│ │ ├── item_folder.png
│ │ └── item_video.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ ├── values
│ │ ├── arrays.xml
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── searchable.xml
│ └── test
│ └── java
│ └── com
│ └── koma
│ └── filemanager
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── koma_key.jks
├── preview
├── screenshot_file_view.png
└── screenshot_main_ui.png
└── settings.gradle
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .metadata/
2 | *~
3 |
4 | # files for the dex VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # generated files
11 | bin/
12 | gen/
13 |
14 | # Local configuration file (sdk path, etc)
15 | local.properties
16 | project.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 | .settings
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Intellij project files
27 | *.iml
28 | *.ipr
29 | *.iws
30 | .idea/
31 |
32 | # Gradle file
33 | .gradle/
34 | apks/
35 | build/
36 | *.iml
37 | .gradle
38 | /local.properties
39 | /.idea/workspace.xml
40 | /.idea/libraries
41 | .DS_Store
42 | /build
43 | /captures
44 | .externalNativeBuild
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FileManager
2 | ===================
3 |
4 | An android open source project about "FileManager".
5 |
6 | #Rxjava + MVP apply to this project.
7 |
8 | 附几张主界面效果图,仅供参考。
9 |
10 |
11 |
12 |
13 | Introduction:
14 | ---
15 | 主界面暂时分为两部分:
16 |
17 | 1.分类文件总览(可显示各类文件的总量)
18 |
19 | 2.挂在设备信息总览
20 |
21 | 子页面:
22 |
23 | 1.查看音频文件
24 |
25 | 2.查看视频文件(To do)
26 |
27 | 3.查看图片文件(To do)
28 |
29 | 4.查看文档文件(To do)
30 |
31 | 5.查看压缩文件
32 |
33 | 6.查看apk文件(To do)
34 |
35 | 7.查看最近添加的文件(To do)
36 |
37 | 8.查看收藏文件(To do)
38 |
39 | 9.密码锁(To do)
40 |
41 | ---
42 |
43 | Licence
44 |
45 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'android-apt'
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 | defaultConfig {
7 | applicationId "com.koma.filemanager"
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | versionCode rootProject.ext.versionCode
11 | versionName rootProject.ext.versionName
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | renderscriptTargetApi rootProject.ext.renderscriptTargetApi
14 | renderscriptSupportModeEnabled true
15 | }
16 | //签名配置
17 | signingConfigs {
18 | release {
19 | storeFile file(STORE_FILE_PATH)
20 | storePassword STORE_PASSWORD
21 | keyAlias KEY_ALIAS
22 | keyPassword KEY_PASSWORD
23 | }
24 | }
25 |
26 | buildTypes {
27 | release {
28 | //是否签名
29 | signingConfig signingConfigs.release
30 | //是否混淆
31 | minifyEnabled false
32 | useProguard false
33 | shrinkResources false // 是否去除无效的资源文件
34 | //是否移除无用资源
35 | zipAlignEnabled true
36 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
37 | }
38 | }
39 |
40 | lintOptions {
41 | disable 'InvalidPackage'
42 | checkReleaseBuilds false
43 | // Or, if you prefer, you can continue to check for errors in release builds,
44 | // but continue the build even when errors are found:
45 | abortOnError false
46 | }
47 | }
48 |
49 | dependencies {
50 | compile fileTree(dir: 'libs', include: ['*.jar'])
51 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
52 | exclude group: 'com.android.support', module: 'support-annotations'
53 | })
54 | compile "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
55 | compile "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
56 | compile "com.android.support:design:$rootProject.ext.supportLibraryVersion"
57 | compile "com.android.support:cardview-v7:$rootProject.ext.supportLibraryVersion"
58 | testCompile 'junit:junit:4.12'
59 |
60 | compile "com.jakewharton:butterknife:$rootProject.ext.butterknife"
61 | apt "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknife"
62 |
63 | compile "com.github.bumptech.glide:glide:$rootProject.ext.glideVersion"
64 |
65 | compile "io.reactivex:rxandroid:$rootProject.ext.rxandroidVersion"
66 | // Because RxAndroid releases are few and far between, it is recommended you also
67 | // explicitly depend on RxJava's latest version for bug fixes and new features.
68 | compile "io.reactivex:rxjava:$rootProject.ext.rxjavaVersion"
69 |
70 | //leakcanary
71 | debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
72 | //releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
73 | releaseCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
74 | testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
75 | }
76 | android.applicationVariants.all { variant ->
77 | variant.outputs.each { output ->
78 | // 删除unaligned apk
79 | if (output.zipAlign != null) {
80 | output.zipAlign.doLast {
81 | output.zipAlign.inputFile.delete()
82 | }
83 | }
84 | }
85 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/koma/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/koma/filemanager/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.koma.filemanager", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
19 |
20 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
42 |
43 |
48 |
52 |
57 |
62 |
63 |
68 |
69 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/FileManagerApplication.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.os.StrictMode;
7 |
8 | import com.squareup.leakcanary.LeakCanary;
9 |
10 | /**
11 | * Created by koma on 11/17/16.
12 | */
13 |
14 | public class FileManagerApplication extends Application {
15 | private static Context sContext;
16 |
17 | @Override
18 | public void onCreate() {
19 | super.onCreate();
20 | sContext = getApplicationContext();
21 | enabledStrictMode();
22 | if (LeakCanary.isInAnalyzerProcess(this)) {
23 | // This process is dedicated to LeakCanary for heap analysis.
24 | // You should not init your app in this process.
25 | return;
26 | }
27 | LeakCanary.install(this);
28 | }
29 |
30 | public static synchronized Context getContext() {
31 | return sContext;
32 | }
33 |
34 | private void enabledStrictMode() {
35 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
36 |
37 | //线程监控,会弹出对话框
38 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
39 | .detectAll()
40 | .penaltyLog()
41 | .penaltyDialog()
42 | .build());
43 |
44 | //VM监控
45 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
46 | .detectAll()
47 | .penaltyLog()
48 | .build());
49 | }
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/archive/ArchiveActivity.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.archive;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v4.app.FragmentTransaction;
6 | import android.support.v7.widget.Toolbar;
7 | import android.text.TextUtils;
8 |
9 | import com.koma.filemanager.R;
10 | import com.koma.filemanager.base.BaseSwipeBackActivity;
11 | import com.koma.filemanager.data.FileRepository;
12 | import com.koma.filemanager.util.LogUtils;
13 |
14 | import butterknife.BindString;
15 | import butterknife.BindView;
16 |
17 | /**
18 | * Created by koma on 12/12/16.
19 | */
20 |
21 | public class ArchiveActivity extends BaseSwipeBackActivity {
22 | private static final String TAG = "ArchiveActivity";
23 | private ArchiveContract.Presenter mPresenter;
24 | private String mPath;
25 | @BindView(R.id.toolbar)
26 | Toolbar mToolbar;
27 | @BindString(R.string.uncompress_to)
28 | String mUnCompressToStr;
29 |
30 | @Override
31 | public void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | LogUtils.i(TAG, "onCreate");
34 | String action = getIntent().getAction();
35 | // 检查action是否正确
36 | if (null == action || !TextUtils.equals(action, Intent.ACTION_VIEW)) {
37 | finish();
38 | }
39 | init();
40 | }
41 |
42 | private void init() {
43 | setSupportActionBar(mToolbar);
44 | ArchiveFragment archiveFragment = (ArchiveFragment) getSupportFragmentManager().findFragmentById(R.id.content);
45 | if (archiveFragment == null) {
46 | archiveFragment = new ArchiveFragment();
47 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
48 | transaction.replace(R.id.content, archiveFragment).commit();
49 | }
50 | mPresenter = new ArchivePresenter(archiveFragment, FileRepository.getInstance());
51 | mPath = mPresenter.getPathFromUri(getIntent().getData());
52 | if (TextUtils.isEmpty(mPath)) {
53 | LogUtils.i(TAG, "the path is empty");
54 | }
55 | }
56 |
57 | @Override
58 | public void onStart() {
59 | super.onStart();
60 | LogUtils.i(TAG, "onStart");
61 | }
62 |
63 | @Override
64 | public void onResume() {
65 | super.onResume();
66 | LogUtils.i(TAG, "onResume");
67 | }
68 |
69 |
70 | @Override
71 | public void onPause() {
72 | super.onPause();
73 | LogUtils.i(TAG, "onPause");
74 | }
75 |
76 | @Override
77 | public void onStop() {
78 | super.onStop();
79 | LogUtils.i(TAG, "onStop");
80 | }
81 |
82 | @Override
83 | public void onDestroy() {
84 | super.onDestroy();
85 | LogUtils.i(TAG, "onDestroy");
86 | if (mPresenter != null) {
87 | mPresenter.unSubscribe();
88 | }
89 | }
90 |
91 | @Override
92 | protected int getLayoutId() {
93 | return R.layout.common_layout;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/archive/ArchiveAdapter.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.archive;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | import com.koma.filemanager.R;
11 | import com.koma.filemanager.data.model.Disk;
12 |
13 | import java.util.List;
14 |
15 | import butterknife.BindView;
16 | import butterknife.ButterKnife;
17 |
18 | /**
19 | * Created by koma on 12/12/16.
20 | */
21 |
22 | public class ArchiveAdapter extends RecyclerView.Adapter {
23 | private static final String TAG = "ArchiveAdapter";
24 | private Context mContext;
25 | private List mData;
26 |
27 | public ArchiveAdapter(Context context, List data) {
28 | mContext = context;
29 | mData = data;
30 | }
31 |
32 | @Override
33 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
34 | View view = LayoutInflater.from(mContext).inflate(R.layout.archive_item_view, null);
35 | return new ViewHolder(view);
36 | }
37 |
38 | @Override
39 | public void onBindViewHolder(ViewHolder holder, int position) {
40 | holder.mVolumeTitle.setText(mData.get(position).getDescription());
41 | }
42 |
43 | @Override
44 | public int getItemCount() {
45 | return mData == null ? 0 : mData.size();
46 | }
47 |
48 | public class ViewHolder extends RecyclerView.ViewHolder {
49 | @BindView(R.id.tv_volume_title)
50 | TextView mVolumeTitle;
51 |
52 | public ViewHolder(View view) {
53 | super(view);
54 | ButterKnife.bind(this, view);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/archive/ArchiveContract.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.archive;
2 |
3 | import android.net.Uri;
4 |
5 | import com.koma.filemanager.base.BasePresenter;
6 | import com.koma.filemanager.base.BaseView;
7 | import com.koma.filemanager.data.model.Disk;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by koma on 12/12/16.
13 | */
14 |
15 | public interface ArchiveContract {
16 | interface View extends BaseView {
17 | void refreshAdapter(ArrayList disks);
18 |
19 | void showCompleted();
20 |
21 | void showError();
22 | }
23 |
24 | interface Presenter extends BasePresenter {
25 | void loadDisks();
26 |
27 | void startArchive();
28 |
29 | void endArchive();
30 |
31 | String getPathFromUri(Uri uri);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/archive/ArchiveFragment.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.archive;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.koma.filemanager.R;
12 | import com.koma.filemanager.base.BaseFragment;
13 | import com.koma.filemanager.data.model.Disk;
14 | import com.koma.filemanager.util.LogUtils;
15 |
16 | import java.util.ArrayList;
17 |
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 |
21 | /**
22 | * Created by koma on 12/12/16.
23 | */
24 |
25 | public class ArchiveFragment extends BaseFragment implements ArchiveContract.View {
26 | private static final String TAG = "ArchiveFragment";
27 | @NonNull
28 | private ArchiveContract.Presenter mPresenter;
29 | @BindView(R.id.recycler_view)
30 | RecyclerView mRecyclerView;
31 | private ArrayList mData;
32 | private ArchiveAdapter mAdapter;
33 |
34 | @Override
35 | public void onActivityCreated(Bundle savedInstanceState) {
36 | super.onActivityCreated(savedInstanceState);
37 | LogUtils.i(TAG, "onActivtyCreated");
38 | }
39 |
40 | @Override
41 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
42 | LogUtils.i(TAG, "onCreateView");
43 | View view = inflater.inflate(R.layout.recyclerview, container, false);
44 | ButterKnife.bind(this, view);
45 | init();
46 | return view;
47 | }
48 |
49 | private void init() {
50 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
51 | linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
52 | mRecyclerView.setLayoutManager(linearLayoutManager);
53 | mData = new ArrayList<>();
54 | mAdapter = new ArchiveAdapter(mContext, mData);
55 | mRecyclerView.setAdapter(mAdapter);
56 |
57 | }
58 |
59 | @Override
60 | public void onViewCreated(View view, Bundle savedInstanceState) {
61 | super.onViewCreated(view, savedInstanceState);
62 | LogUtils.i(TAG, "onViewCreated");
63 | if (mPresenter != null) {
64 | mPresenter.subscribe();
65 | }
66 | }
67 |
68 | @Override
69 | public void onResume() {
70 | super.onResume();
71 | LogUtils.i(TAG, "onResume");
72 | if (mPresenter != null) {
73 | mPresenter.loadDisks();
74 | }
75 | }
76 |
77 | @Override
78 | public void onDestroyView() {
79 | super.onDestroyView();
80 | LogUtils.i(TAG, "onDestroyView");
81 | if (mPresenter != null) {
82 | mPresenter.unSubscribe();
83 | }
84 | }
85 |
86 | @Override
87 | public void refreshAdapter(ArrayList disks) {
88 | LogUtils.i(TAG, "refershAdapter");
89 | if (mData != null) {
90 | mData.clear();
91 | } else {
92 | mData = new ArrayList<>();
93 | }
94 | mData.addAll(disks);
95 | mAdapter.notifyDataSetChanged();
96 | }
97 |
98 | @Override
99 | public void showCompleted() {
100 | LogUtils.i(TAG, "showCompleted");
101 | }
102 |
103 | @Override
104 | public void showError() {
105 | LogUtils.i(TAG, "showError");
106 | }
107 |
108 | @Override
109 | public void setPresenter(@NonNull ArchiveContract.Presenter presenter) {
110 | LogUtils.i(TAG, "setPresenter");
111 | mPresenter = presenter;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/archive/ArchivePresenter.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.archive;
2 |
3 |
4 | import android.content.ContentResolver;
5 | import android.net.Uri;
6 | import android.support.annotation.NonNull;
7 |
8 | import com.koma.filemanager.data.FileRepository;
9 | import com.koma.filemanager.data.model.Disk;
10 | import com.koma.filemanager.util.LogUtils;
11 |
12 | import java.util.ArrayList;
13 |
14 | import rx.Subscriber;
15 | import rx.Subscription;
16 | import rx.android.schedulers.AndroidSchedulers;
17 | import rx.schedulers.Schedulers;
18 | import rx.subscriptions.CompositeSubscription;
19 |
20 | /**
21 | * Created by koma on 12/12/16.
22 | */
23 |
24 | public class ArchivePresenter implements ArchiveContract.Presenter {
25 | private static final String TAG = "ArchivePresenter";
26 | @NonNull
27 | private ArchiveContract.View mView;
28 | @NonNull
29 | private FileRepository mRespository;
30 | private CompositeSubscription mSubsriptions;
31 | private Subscription mDisksSubscription;
32 |
33 | public ArchivePresenter(@NonNull ArchiveContract.View view, FileRepository repository) {
34 | mView = view;
35 | mView.setPresenter(this);
36 | mRespository = repository;
37 | }
38 |
39 | private Subscriber> mDisksSubscriber = new Subscriber>() {
40 | @Override
41 | public void onCompleted() {
42 | LogUtils.i(TAG, "onCompleted");
43 | }
44 |
45 | @Override
46 | public void onError(Throwable e) {
47 | LogUtils.i(TAG, "onError :" + e.toString());
48 | }
49 |
50 | @Override
51 | public void onNext(ArrayList disks) {
52 | LogUtils.i(TAG, "onNext");
53 | if (mView != null) {
54 | mView.refreshAdapter(disks);
55 | }
56 | }
57 |
58 | };
59 |
60 | @Override
61 | public void loadDisks() {
62 | if (mSubsriptions != null && mDisksSubscription != null) {
63 | mSubsriptions.remove(mDisksSubscription);
64 | }
65 | mDisksSubscription = mRespository.getDisks().subscribeOn(Schedulers.io())
66 | .observeOn(AndroidSchedulers.mainThread())
67 | .subscribe(mDisksSubscriber);
68 | mSubsriptions.add(mDisksSubscription);
69 | }
70 |
71 | @Override
72 | public void startArchive() {
73 | LogUtils.i(TAG, "startArchive");
74 | }
75 |
76 | @Override
77 | public void endArchive() {
78 | LogUtils.i(TAG, "endArchive");
79 | }
80 |
81 | @Override
82 | public void subscribe() {
83 | LogUtils.i(TAG, "subscribe");
84 | if (mSubsriptions == null) {
85 | mSubsriptions = new CompositeSubscription();
86 | }
87 | }
88 |
89 | @Override
90 | public String getPathFromUri(Uri uri) {
91 | if (null == uri) {
92 | return null;
93 | }
94 | final String scheme = uri.getScheme();
95 | String path = null;
96 | if (null == scheme || ContentResolver.SCHEME_FILE.equals(scheme)) {
97 | path = uri.getPath();
98 | }
99 | return path;
100 | }
101 |
102 | @Override
103 | public void unSubscribe() {
104 | LogUtils.i(TAG, "unSubscribe");
105 | if (mSubsriptions != null) {
106 | mSubsriptions.clear();
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/audio/AudioActivity.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.audio;
2 |
3 | import android.database.ContentObserver;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.support.v4.app.FragmentTransaction;
7 | import android.support.v7.widget.Toolbar;
8 |
9 | import com.koma.filemanager.R;
10 | import com.koma.filemanager.base.BaseMenuActivity;
11 | import com.koma.filemanager.data.FileRepository;
12 | import com.koma.filemanager.util.FileCategoryUtils;
13 | import com.koma.filemanager.util.LogUtils;
14 |
15 | import butterknife.BindView;
16 |
17 | /**
18 | * Created by koma on 11/19/16.
19 | */
20 |
21 | public class AudioActivity extends BaseMenuActivity {
22 | private static final String TAG = "AudioActivity";
23 | AudioPresenter mPresenter;
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | LogUtils.i(TAG, "onCreate");
29 | init();
30 | }
31 |
32 | private void init() {
33 | AudioFragment audioFragment = (AudioFragment) getSupportFragmentManager().findFragmentById(R.id.content);
34 | if (audioFragment == null) {
35 | audioFragment = new AudioFragment();
36 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
37 | transaction.replace(R.id.content, audioFragment).commit();
38 | }
39 | mPresenter = new AudioPresenter(audioFragment, FileRepository.getInstance());
40 | getContentResolver().registerContentObserver(FileCategoryUtils.getAudioUri(), true, mAudioObserver);
41 | }
42 |
43 | private final ContentObserver mAudioObserver = new ContentObserver(new Handler()) {
44 | @Override
45 | public void onChange(boolean selfChange) {
46 | super.onChange(selfChange);
47 | LogUtils.i(TAG, "Audio uri change so refresh");
48 | if (mPresenter != null) {
49 | mPresenter.getAudioFiles();
50 | }
51 | }
52 | };
53 |
54 | @Override
55 | public void onStart() {
56 | super.onStart();
57 | LogUtils.i(TAG, "onStart");
58 | }
59 |
60 | @Override
61 | public void onResume() {
62 | super.onResume();
63 | LogUtils.i(TAG, "onResume");
64 | }
65 |
66 | @Override
67 | public void onPause() {
68 | super.onPause();
69 | LogUtils.i(TAG, "onPause");
70 | }
71 |
72 | @Override
73 | public void onStop() {
74 | super.onStop();
75 | LogUtils.i(TAG, "onStop");
76 | }
77 |
78 | @Override
79 | public void onDestroy() {
80 | super.onDestroy();
81 | LogUtils.i(TAG, "onDestroy");
82 | if (mAudioObserver != null) {
83 | getContentResolver().unregisterContentObserver(mAudioObserver);
84 | }
85 | }
86 |
87 | @Override
88 | protected int getLayoutId() {
89 | return R.layout.common_layout;
90 | }
91 |
92 | @Override
93 | protected void sortByType() {
94 |
95 | }
96 |
97 | @Override
98 | protected void sortByName() {
99 |
100 | }
101 |
102 | @Override
103 | protected void sortBySize() {
104 |
105 | }
106 |
107 | @Override
108 | protected void sortByDate() {
109 |
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/audio/AudioAdapter.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.audio;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.CheckBox;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | import com.bumptech.glide.Glide;
13 | import com.koma.filemanager.R;
14 | import com.koma.filemanager.data.model.AudioFile;
15 | import com.koma.filemanager.helper.MeidaHelper;
16 | import com.koma.filemanager.util.FileUtils;
17 | import com.koma.filemanager.util.LogUtils;
18 |
19 | import java.util.ArrayList;
20 |
21 | import butterknife.BindView;
22 | import butterknife.ButterKnife;
23 | import butterknife.OnClick;
24 |
25 | /**
26 | * Created by koma on 11/24/16.
27 | */
28 |
29 | public class AudioAdapter extends RecyclerView.Adapter {
30 | private static final String TAG = "AudioAdapter";
31 | private ArrayList mData;
32 | private Context mContext;
33 |
34 | public AudioAdapter(Context context, ArrayList data) {
35 | mContext = context;
36 | mData = data;
37 | }
38 |
39 | public void setData(ArrayList data) {
40 | if (mData != null) {
41 | mData.clear();
42 | } else {
43 | mData = new ArrayList<>();
44 | }
45 | mData.addAll(data);
46 | notifyDataSetChanged();
47 | }
48 |
49 | @Override
50 | public AudioViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
51 | View view = LayoutInflater.from(mContext).inflate(R.layout.item_view, null);
52 | return new AudioViewHolder(view);
53 | }
54 |
55 |
56 | @Override
57 | public int getItemCount() {
58 | return mData == null ? 0 : mData.size();
59 | }
60 |
61 | @Override
62 | public void onBindViewHolder(AudioViewHolder holder, int position) {
63 | Glide.with(mContext).load(MeidaHelper.getAlbumArtUri(mData.get(position).getAlbumId()))
64 | .placeholder(R.mipmap.item_audio)
65 | .crossFade(1000).into(holder.mFileImage);
66 | holder.mFileName.setText(mData.get(position).getFileName());
67 | holder.mFileSize.setText(FileUtils.formatFileSize(mData.get(position).getFileSize()));
68 | holder.mFileModifiedTime.setText(FileUtils.formatFileModifiedTime(mData.get(position).getFileModifiedTime()));
69 | }
70 |
71 | public class AudioViewHolder extends RecyclerView.ViewHolder {
72 | @BindView(R.id.select_checkbox)
73 | CheckBox mSelectBox;
74 | @BindView(R.id.iv_file_image)
75 | ImageView mFileImage;
76 | @BindView(R.id.tv_file_name)
77 | TextView mFileName;
78 | @BindView(R.id.tv_file_size)
79 | TextView mFileSize;
80 | @BindView(R.id.tv_file_modified_time)
81 | TextView mFileModifiedTime;
82 |
83 | public AudioViewHolder(View view) {
84 | super(view);
85 | ButterKnife.bind(this, view);
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/audio/AudioConstract.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.audio;
2 |
3 | import com.koma.filemanager.base.BasePresenter;
4 | import com.koma.filemanager.base.BaseView;
5 | import com.koma.filemanager.data.model.AudioFile;
6 |
7 | import java.util.ArrayList;
8 |
9 | import rx.Observable;
10 |
11 | /**
12 | * Created by koma on 11/16/16.
13 | */
14 |
15 | public interface AudioConstract {
16 | interface View extends BaseView {
17 | void refreshAdapter(ArrayList audioFiles);
18 |
19 | void showLoadingView();
20 |
21 | void hideLoadingView();
22 |
23 | void showEmptyView();
24 | }
25 |
26 | interface Presenter extends BasePresenter {
27 | void getAudioFiles();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/audio/AudioPlayerActivity.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.audio;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import com.koma.filemanager.base.BaseSwipeBackActivity;
7 | import com.koma.filemanager.util.LogUtils;
8 |
9 | /**
10 | * Created by koma on 11/29/16.
11 | */
12 |
13 | public class AudioPlayerActivity extends BaseSwipeBackActivity {
14 | private static String TAG = "AudioPlayerActivity";
15 |
16 | public void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | LogUtils.i(TAG, "onCreate");
19 | getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
20 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
21 | }
22 |
23 | @Override
24 | protected int getLayoutId() {
25 | return 0;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/audio/AudioPresenter.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.audio;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import com.koma.filemanager.data.FileRepository;
6 | import com.koma.filemanager.data.model.AudioFile;
7 | import com.koma.filemanager.util.LogUtils;
8 |
9 | import java.util.ArrayList;
10 |
11 | import rx.Subscriber;
12 | import rx.Subscription;
13 | import rx.android.schedulers.AndroidSchedulers;
14 | import rx.schedulers.Schedulers;
15 | import rx.subscriptions.CompositeSubscription;
16 |
17 | /**
18 | * Created by koma on 11/24/16.
19 | */
20 |
21 | public class AudioPresenter implements AudioConstract.Presenter {
22 | private static final String TAG = "AudioPresenter";
23 | private CompositeSubscription mSubscription;
24 | @NonNull
25 | private AudioConstract.View mView;
26 | @NonNull
27 | private FileRepository mFileRepository;
28 | private Subscription mAudioFilesSubsription;
29 |
30 | public AudioPresenter(@NonNull AudioConstract.View view, @NonNull FileRepository repository) {
31 | mFileRepository = repository;
32 | mView = view;
33 | mSubscription = new CompositeSubscription();
34 | mView.setPresenter(this);
35 | }
36 |
37 | @Override
38 | public void subscribe() {
39 | LogUtils.i(TAG, "subscribe");
40 | getAudioFiles();
41 | }
42 |
43 | @Override
44 | public void unSubscribe() {
45 | LogUtils.i(TAG, "unSubscribe");
46 | if (mSubscription != null) {
47 | mSubscription.clear();
48 | }
49 | }
50 |
51 | @Override
52 | public void getAudioFiles() {
53 | if (mSubscription != null && mAudioFilesSubsription != null) {
54 | mSubscription.remove(mAudioFilesSubsription);
55 | }
56 | mAudioFilesSubsription = mFileRepository.getAudioFiles().subscribeOn(Schedulers.io())
57 | .observeOn(AndroidSchedulers.mainThread())
58 | .subscribe(new Subscriber>() {
59 | @Override
60 | public void onCompleted() {
61 | LogUtils.i(TAG, "onCompleted Thread id : " + Thread.currentThread().getId());
62 | }
63 |
64 | @Override
65 | public void onError(Throwable e) {
66 | LogUtils.e(TAG, "error : " + e.toString());
67 | }
68 |
69 | @Override
70 | public void onNext(ArrayList audioFiles) {
71 | LogUtils.i(TAG, "onNext Thread id : " + Thread.currentThread().getId());
72 | if (mView != null) {
73 | if (audioFiles.size() == 0) {
74 | mView.showEmptyView();
75 | } else {
76 | mView.hideLoadingView();
77 | }
78 | mView.refreshAdapter(audioFiles);
79 | }
80 | }
81 | });
82 | mSubscription.add(mAudioFilesSubsription);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.base;
2 |
3 | import android.Manifest;
4 | import android.content.Context;
5 | import android.content.pm.PackageManager;
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.v4.app.ActivityCompat;
9 | import android.support.v4.content.ContextCompat;
10 | import android.support.v7.app.AppCompatActivity;
11 |
12 | import com.koma.filemanager.util.LogUtils;
13 |
14 | import butterknife.ButterKnife;
15 | import rx.Subscription;
16 | import rx.subscriptions.CompositeSubscription;
17 |
18 | import static com.koma.filemanager.util.Constants.PERMISSIONS_STORAGE;
19 | import static com.koma.filemanager.util.Constants.REQUEST_CODE_ASK_PERMISSIONS;
20 |
21 | /**
22 | * Created by koma on 11/16/16.
23 | */
24 |
25 | public abstract class BaseActivity extends AppCompatActivity {
26 | private static final String TAG = "BaseActivity";
27 | protected Context mContext;
28 | private CompositeSubscription mSubscriptions;
29 |
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | LogUtils.i(TAG, "onCreate");
33 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
34 | != PackageManager.PERMISSION_GRANTED ||
35 | ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
36 | != PackageManager.PERMISSION_GRANTED) {
37 | requestStoragePermissions();
38 | }
39 | mContext = BaseActivity.this;
40 | setContentView(getLayoutId());
41 | ButterKnife.bind(this);
42 | }
43 |
44 | @Override
45 | protected void onDestroy() {
46 | super.onDestroy();
47 | if (mSubscriptions != null) {
48 | mSubscriptions.clear();
49 | }
50 | }
51 |
52 | protected abstract int getLayoutId();
53 |
54 | private void requestStoragePermissions() {
55 | if (ActivityCompat.shouldShowRequestPermissionRationale(this,
56 | Manifest.permission.READ_EXTERNAL_STORAGE)
57 | || ActivityCompat.shouldShowRequestPermissionRationale(this,
58 | Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
59 | ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_CODE_ASK_PERMISSIONS);
60 | } else {
61 | // Contact permissions have not been granted yet. Request them directly.
62 | ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_CODE_ASK_PERMISSIONS);
63 | }
64 | }
65 |
66 | /**
67 | * Callback received when a permissions request has been completed.
68 | */
69 | @Override
70 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
71 | @NonNull int[] grantResults) {
72 |
73 | if (requestCode == REQUEST_CODE_ASK_PERMISSIONS) {
74 | // Check if the only required permission has been granted
75 | if (!verifyPermissions(grantResults)) {
76 | this.finish();
77 | }
78 | }
79 | }
80 |
81 | private boolean verifyPermissions(int[] grantResults) {
82 | // At least one result must be checked.
83 | if (grantResults.length < 1) {
84 | return false;
85 | }
86 |
87 | // Verify that each required permission has been granted, otherwise return false.
88 | for (int result : grantResults) {
89 | if (result != PackageManager.PERMISSION_GRANTED) {
90 | return false;
91 | }
92 | }
93 | return true;
94 | }
95 |
96 | protected void addSubscription(Subscription subscription) {
97 | if (subscription == null) return;
98 | if (mSubscriptions == null) {
99 | mSubscriptions = new CompositeSubscription();
100 | }
101 | mSubscriptions.add(subscription);
102 | }
103 |
104 | protected void clearSubsription() {
105 | if (mSubscriptions != null) {
106 | mSubscriptions.clear();
107 | }
108 | }
109 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/base/BaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.base;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 |
6 | /**
7 | * Created by koma on 12/27/16.
8 | */
9 |
10 | public abstract class BaseAdapter extends RecyclerView.Adapter {
11 | private static final String TAG = BaseAdapter.class.getSimpleName();
12 | private Context mContext;
13 | public OnItemClickListener mItemClickListener;
14 | public OnItemLongClickListener mItemLongClickListener;
15 |
16 | public BaseAdapter(Context context) {
17 | mContext = context;
18 | }
19 |
20 | public void setOnItemClickListener(OnItemClickListener listener) {
21 | mItemClickListener = listener;
22 | }
23 |
24 | public void setOnItemLongClickListener(OnItemLongClickListener listener) {
25 | mItemLongClickListener = listener;
26 | }
27 |
28 | public interface OnItemClickListener {
29 | boolean onItemClick(int position);
30 | }
31 |
32 |
33 | public interface OnItemLongClickListener {
34 | void onItemLongClick(int position);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/base/BaseFile.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.base;
2 |
3 | import com.koma.filemanager.helper.FileHelper;
4 |
5 | import java.io.File;
6 | import java.util.Date;
7 |
8 | /**
9 | * Created by koma on 11/23/16.
10 | */
11 |
12 | public class BaseFile implements Comparable {
13 | private String mFileName;
14 | private Date mFileModifiedTime;
15 | private long mFileSize;
16 | private String mParent;
17 | private boolean mIsDirectory;
18 |
19 | public BaseFile(String fileName, String parent, long fileSize, Date fileModifiedTime) {
20 | mFileName = fileName;
21 | mFileSize = fileSize;
22 | mFileModifiedTime = fileModifiedTime;
23 | mParent = parent;
24 | mIsDirectory = true;
25 | }
26 |
27 | public BaseFile(String fileName, String parent, long fileSize, Date fileModifiedTime, boolean isDirectory) {
28 | mFileName = fileName;
29 | mFileSize = fileSize;
30 | mFileModifiedTime = fileModifiedTime;
31 | mParent = parent;
32 | mIsDirectory = isDirectory;
33 | }
34 |
35 |
36 | public void setFileName(String fileName) {
37 | mFileName = fileName;
38 | }
39 |
40 | public String getFileName() {
41 | return mFileName;
42 | }
43 |
44 | public void setFileSize(long fileSize) {
45 | mFileSize = fileSize;
46 | }
47 |
48 | public long getFileSize() {
49 | return mFileSize;
50 | }
51 |
52 | public void setFileModifiedTime(Date modifiedTime) {
53 | mFileModifiedTime = modifiedTime;
54 | }
55 |
56 | public Date getFileModifiedTime() {
57 | return mFileModifiedTime;
58 | }
59 |
60 | public void setParent(String parent) {
61 | mParent = parent;
62 | }
63 |
64 | public String getParent() {
65 | return mParent;
66 | }
67 |
68 | public boolean getIsDirectory() {
69 | return mIsDirectory;
70 | }
71 |
72 | public void setIsDirectory(boolean isDirectory) {
73 | mIsDirectory = isDirectory;
74 | }
75 |
76 | public String getFullPath() {
77 | StringBuilder stringBuilder = new StringBuilder(mParent);
78 | if (FileHelper.isRootDirectory(this)) {
79 | return FileHelper.ROOT_DIRECTORY;
80 | } else if (FileHelper.isParentRootDirectory(this)) {
81 | if (this.mParent == null) {
82 | return FileHelper.ROOT_DIRECTORY + mFileName;
83 | }
84 | return stringBuilder.append(mFileName).toString();
85 | }
86 | return stringBuilder.append(File.separator).append(mFileName).toString();
87 | }
88 |
89 | @Override
90 | public int compareTo(BaseFile another) {
91 | String o1 = this.getFullPath();
92 | String o2 = another.getFullPath();
93 | return o1.compareTo(o2);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.base;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.View;
8 |
9 | import com.koma.filemanager.R;
10 | import com.koma.filemanager.util.LogUtils;
11 | import com.koma.filemanager.widget.LoadingView;
12 |
13 | import butterknife.BindView;
14 | import butterknife.ButterKnife;
15 | import rx.Subscription;
16 | import rx.subscriptions.CompositeSubscription;
17 |
18 | /**
19 | * Created by koma on 11/16/16.
20 | */
21 |
22 | public class BaseFragment extends Fragment {
23 | private static final String TAG = "BaseFragment";
24 | protected Context mContext;
25 | private CompositeSubscription mSubscriptions;
26 | @BindView(R.id.loading_view)
27 | LoadingView mLoadingView;
28 |
29 | @Override
30 | public void onAttach(Context context) {
31 | super.onAttach(context);
32 | LogUtils.i(TAG, "onAttach");
33 | mContext = context;
34 | }
35 |
36 | @Override
37 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
38 | super.onViewCreated(view, savedInstanceState);
39 | ButterKnife.bind(this, view);
40 | }
41 |
42 | @Override
43 | public void onDestroyView() {
44 | super.onDestroyView();
45 | if (mSubscriptions != null) {
46 | mSubscriptions.clear();
47 | }
48 | }
49 |
50 | protected void showLoadingView() {
51 | mLoadingView.post(new Runnable() {
52 | @Override
53 | public void run() {
54 | mLoadingView.showLoding();
55 | }
56 | });
57 | }
58 |
59 | protected void hideLodingView() {
60 | mLoadingView.post(new Runnable() {
61 | @Override
62 | public void run() {
63 | mLoadingView.hideLoading();
64 | }
65 | });
66 | }
67 |
68 | protected void showLoadingEmpty() {
69 | mLoadingView.post(new Runnable() {
70 | @Override
71 | public void run() {
72 | mLoadingView.showLoadingEmpty();
73 | }
74 | });
75 | }
76 |
77 | protected void addSubscription(Subscription subscription) {
78 | if (subscription == null) return;
79 | if (mSubscriptions == null) {
80 | mSubscriptions = new CompositeSubscription();
81 | }
82 | mSubscriptions.add(subscription);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/base/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.base;
2 |
3 | /**
4 | * Created by koma on 11/16/16.
5 | */
6 |
7 | public interface BasePresenter {
8 | void subscribe();
9 |
10 | void unSubscribe();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/base/BaseSwipeBackActivity.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.base;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.koma.filemanager.util.LogUtils;
6 |
7 | /**
8 | * Created by koma on 11/16/16.
9 | */
10 |
11 | public abstract class BaseSwipeBackActivity extends BaseActivity {
12 | private static final String TAG = "BaseSwipeBackActivity";
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | LogUtils.i(TAG, "onCreate");
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/base/BaseView.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.base;
2 |
3 | /**
4 | * Created by koma on 11/16/16.
5 | */
6 |
7 | public interface BaseView {
8 | void setPresenter(T presenter);
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/base/BaseViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.base;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | import com.koma.filemanager.util.LogUtils;
7 |
8 | import butterknife.ButterKnife;
9 |
10 | /**
11 | * Created by koma on 12/26/16.
12 | */
13 |
14 | public class BaseViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,
15 | View.OnLongClickListener {
16 | private static final String TAG = BaseViewHolder.class.getSimpleName();
17 | protected final BaseAdapter mAdapter;
18 |
19 |
20 | public BaseViewHolder(View view, BaseAdapter adapter) {
21 | super(view);
22 | this.mAdapter = adapter;
23 | ButterKnife.bind(this, view);
24 | view.setOnClickListener(this);
25 | view.setOnLongClickListener(this);
26 | }
27 |
28 | public View getItemView() {
29 | return itemView;
30 | }
31 |
32 | public int getBaseViewHolderPosition() {
33 | return getAdapterPosition();
34 | }
35 |
36 |
37 | @Override
38 | public void onClick(View v) {
39 | if (mAdapter != null) {
40 | mAdapter.mItemClickListener.onItemClick(getBaseViewHolderPosition());
41 | }
42 | }
43 |
44 | @Override
45 | public boolean onLongClick(View v) {
46 | if (mAdapter != null) {
47 | LogUtils.i(TAG, "onItemLongClickListener position : " + getBaseViewHolderPosition());
48 | mAdapter.mItemLongClickListener.onItemLongClick(getBaseViewHolderPosition());
49 | return true;
50 | }
51 | return false;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/FileDataSource.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data;
2 |
3 | import com.koma.filemanager.base.BaseFile;
4 | import com.koma.filemanager.data.model.ApkFile;
5 | import com.koma.filemanager.data.model.AudioFile;
6 | import com.koma.filemanager.data.model.Disk;
7 | import com.koma.filemanager.data.model.DocumentFile;
8 | import com.koma.filemanager.data.model.ImageFile;
9 | import com.koma.filemanager.data.model.VideoFile;
10 | import com.koma.filemanager.data.model.ZipFile;
11 |
12 | import java.util.ArrayList;
13 |
14 | import rx.Observable;
15 |
16 | /**
17 | * Created by koma on 11/25/16.
18 | */
19 |
20 | public interface FileDataSource {
21 | Observable getAuidoCounts();
22 |
23 | Observable getVideoCounts();
24 |
25 | Observable getImageCounts();
26 |
27 | Observable getDocumentsCounts();
28 |
29 | Observable getZipCounts();
30 |
31 | Observable getApkCounts();
32 |
33 | Observable> getDisks();
34 |
35 | Observable> getAudioFiles();
36 |
37 | Observable> getImageFiles();
38 |
39 | Observable> getVideoFiles();
40 |
41 | Observable> getDocumentFiles();
42 |
43 | Observable> getZipFiles();
44 |
45 | Observable> getApkFiles();
46 |
47 | Observable> getFiles(String path);
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/FileRepository.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data;
2 |
3 | import com.koma.filemanager.FileManagerApplication;
4 | import com.koma.filemanager.base.BaseFile;
5 | import com.koma.filemanager.data.model.ApkFile;
6 | import com.koma.filemanager.data.model.AudioFile;
7 | import com.koma.filemanager.data.model.Disk;
8 | import com.koma.filemanager.data.model.DocumentFile;
9 | import com.koma.filemanager.data.model.ImageFile;
10 | import com.koma.filemanager.data.model.VideoFile;
11 | import com.koma.filemanager.data.model.ZipFile;
12 |
13 | import java.util.ArrayList;
14 |
15 | import rx.Observable;
16 |
17 | /**
18 | * Created by koma on 11/25/16.
19 | */
20 |
21 | public class FileRepository implements FileDataSource {
22 | private static volatile FileRepository sRespository;
23 | private LocalDataSource mLocalDataSource;
24 |
25 | private FileRepository() {
26 | mLocalDataSource = new LocalDataSource(FileManagerApplication.getContext());
27 | }
28 |
29 | public static FileRepository getInstance() {
30 | if (sRespository == null) {
31 | synchronized (FileRepository.class) {
32 | if (sRespository == null) {
33 | sRespository = new FileRepository();
34 | }
35 | }
36 | }
37 | return sRespository;
38 | }
39 |
40 | @Override
41 | public Observable getAuidoCounts() {
42 | return mLocalDataSource.getAuidoCounts();
43 | }
44 |
45 | @Override
46 | public Observable getVideoCounts() {
47 | return mLocalDataSource.getVideoCounts();
48 | }
49 |
50 | @Override
51 | public Observable getImageCounts() {
52 | return mLocalDataSource.getImageCounts();
53 | }
54 |
55 | @Override
56 | public Observable getDocumentsCounts() {
57 | return mLocalDataSource.getDocumentsCounts();
58 | }
59 |
60 | @Override
61 | public Observable getZipCounts() {
62 | return mLocalDataSource.getZipCounts();
63 | }
64 |
65 | @Override
66 | public Observable getApkCounts() {
67 | return mLocalDataSource.getApkCounts();
68 | }
69 |
70 | @Override
71 | public Observable> getDisks() {
72 | return mLocalDataSource.getDisks();
73 | }
74 |
75 | @Override
76 | public Observable> getAudioFiles() {
77 | return mLocalDataSource.getAudioFiles();
78 | }
79 |
80 | @Override
81 | public Observable> getImageFiles() {
82 | return mLocalDataSource.getImageFiles();
83 | }
84 |
85 | @Override
86 | public Observable> getVideoFiles() {
87 | return mLocalDataSource.getVideoFiles();
88 | }
89 |
90 | @Override
91 | public Observable> getDocumentFiles() {
92 | return null;
93 | }
94 |
95 | @Override
96 | public Observable> getZipFiles() {
97 | return mLocalDataSource.getZipFiles();
98 | }
99 |
100 | @Override
101 | public Observable> getApkFiles() {
102 | return null;
103 | }
104 |
105 | @Override
106 | public Observable> getFiles(String path) {
107 | return mLocalDataSource.getFiles(path);
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/model/ApkFile.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data.model;
2 |
3 | import com.koma.filemanager.base.BaseFile;
4 |
5 | /**
6 | * Created by koma on 11/28/16.
7 | */
8 |
9 | public class ApkFile extends BaseFile {
10 | public ApkFile(){
11 | super("", "", 0, null);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/model/AudioFile.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data.model;
2 |
3 | import com.koma.filemanager.base.BaseFile;
4 |
5 | import java.util.Date;
6 |
7 | /**
8 | * Created by koma on 11/23/16.
9 | */
10 |
11 | public class AudioFile extends BaseFile {
12 | private long mAlbumId;
13 | private String mDisplayName;
14 |
15 | public AudioFile() {
16 | super("", "", 0, null);
17 | mDisplayName = "";
18 | }
19 |
20 | public AudioFile(String fileName, String parent, long fileSize, Date fileModifiedTime, String displayName) {
21 | super(fileName, parent, fileSize, fileModifiedTime);
22 | mDisplayName = displayName;
23 | }
24 |
25 | public void setDisplayName(String displayName) {
26 | mDisplayName = displayName;
27 | }
28 |
29 | public String getDisplayTime() {
30 | return mDisplayName;
31 | }
32 |
33 | public long getAlbumId() {
34 | return mAlbumId;
35 | }
36 |
37 | public void setAlbumId(long albumId) {
38 | mAlbumId = albumId;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/model/Disk.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data.model;
2 |
3 | /**
4 | * Created by koma on 11/29/16.
5 | */
6 |
7 | public class Disk {
8 | private String mMountPoint, mDescription;
9 | private long mTotalSpace, mVailableSpace;
10 |
11 | public Disk() {
12 | this("", "", 0, 0);
13 | }
14 |
15 | public Disk(String mountPoint, String description, long total, long vailableSpace) {
16 | mMountPoint = mountPoint;
17 | mDescription = description;
18 | mTotalSpace = total;
19 | mVailableSpace = vailableSpace;
20 | }
21 |
22 | public void setMountPoint(String mountPoint) {
23 | mMountPoint = mountPoint;
24 | }
25 |
26 | public String getMountPoint() {
27 | return mMountPoint;
28 | }
29 |
30 | public void setDescription(String description) {
31 | mDescription = description;
32 | }
33 |
34 | public String getDescription() {
35 | return mDescription;
36 | }
37 |
38 | public void setTotalSpace(long totalSpace) {
39 | mTotalSpace = totalSpace;
40 | }
41 |
42 | public long getTotalSpace() {
43 | return mTotalSpace;
44 | }
45 |
46 | public void setAvailableSpace(long availableSpace) {
47 | mVailableSpace = availableSpace;
48 | }
49 |
50 | public long getAvailavleSpace() {
51 | return mVailableSpace;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/model/DocumentFile.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data.model;
2 |
3 | import com.koma.filemanager.base.BaseFile;
4 |
5 | /**
6 | * Created by koma on 11/28/16.
7 | */
8 |
9 | public class DocumentFile extends BaseFile {
10 | public DocumentFile() {
11 | super("", "", 0, null);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/model/ImageFile.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data.model;
2 |
3 | /**
4 | * Created by koma on 11/23/16.
5 | */
6 |
7 | public class ImageFile {
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/model/VideoFile.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data.model;
2 |
3 | /**
4 | * Created by koma on 11/23/16.
5 | */
6 |
7 | public class VideoFile {
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/data/model/ZipFile.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.data.model;
2 |
3 | import com.koma.filemanager.base.BaseFile;
4 |
5 | /**
6 | * Created by koma on 11/28/16.
7 | */
8 |
9 | public class ZipFile extends BaseFile {
10 | public ZipFile() {
11 | super("", "", 0, null);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/filecategory/FileCategoryActivity.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.filecategory;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.FragmentTransaction;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.text.TextUtils;
8 |
9 | import com.koma.filemanager.R;
10 | import com.koma.filemanager.base.BaseMenuActivity;
11 | import com.koma.filemanager.data.FileRepository;
12 | import com.koma.filemanager.data.model.ZipFile;
13 | import com.koma.filemanager.util.Constants;
14 | import com.koma.filemanager.util.LogUtils;
15 |
16 | import java.util.ArrayList;
17 |
18 | import butterknife.BindView;
19 |
20 | /**
21 | * Created by koma on 12/12/16.
22 | */
23 |
24 | public class FileCategoryActivity extends BaseMenuActivity {
25 | private static final String TAG = "FileCategoryActivity";
26 | private String mCategory;
27 | private FileCategoryContract.Presenter mPresenter;
28 | private FileCategoryAdapter mAdapter;
29 | private ArrayList mData;
30 |
31 | @Override
32 | public void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | LogUtils.i(TAG, "onCreate");
35 | if (getIntent().getExtras() != null) {
36 | mCategory = getIntent().getStringExtra(Constants.FILE_CATEGORY);
37 | }
38 | if (mCategory == null) {
39 | finish();
40 | }
41 | LogUtils.i(TAG, "mCategory : " + mCategory);
42 | init();
43 | }
44 |
45 | private void init() {
46 | FileCategoryFragment fileCategoryFragment = (FileCategoryFragment) getSupportFragmentManager().findFragmentById(R.id.content);
47 | if (fileCategoryFragment == null) {
48 | fileCategoryFragment = new FileCategoryFragment();
49 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
50 | transaction.replace(R.id.content, fileCategoryFragment).commit();
51 | }
52 | mPresenter = new FileCategoryPresenter(fileCategoryFragment, FileRepository.getInstance());
53 | }
54 |
55 | @Override
56 | public void onStart() {
57 | super.onStart();
58 | LogUtils.i(TAG, "onStart");
59 | }
60 |
61 | @Override
62 | public void onResume() {
63 | super.onResume();
64 | LogUtils.i(TAG, "onResume");
65 | if (TextUtils.equals(mCategory, "zip")) {
66 | if (mPresenter != null) {
67 | mPresenter.getZipFiles();
68 | }
69 | }
70 | }
71 |
72 | @Override
73 | public void onPause() {
74 | super.onPause();
75 | LogUtils.i(TAG, "onPause");
76 | }
77 |
78 | @Override
79 | public void onStop() {
80 | super.onStop();
81 | LogUtils.i(TAG, "onStop");
82 | }
83 |
84 | @Override
85 | public void onDestroy() {
86 | super.onDestroy();
87 | LogUtils.i(TAG, "onDestroy");
88 | if (mPresenter != null) {
89 | mPresenter.unSubscribe();
90 | }
91 | }
92 |
93 | @Override
94 | protected void sortByType() {
95 | LogUtils.i(TAG, "sortbyType");
96 | }
97 |
98 | @Override
99 | protected void sortByName() {
100 | LogUtils.i(TAG, "sortByName");
101 | }
102 |
103 | @Override
104 | protected void sortBySize() {
105 | LogUtils.i(TAG, "sortBySize");
106 | }
107 |
108 | @Override
109 | protected void sortByDate() {
110 | LogUtils.i(TAG, "sortByDate");
111 | }
112 |
113 | @Override
114 | protected int getLayoutId() {
115 | return R.layout.common_layout;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/filecategory/FileCategoryContract.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.filecategory;
2 |
3 | import com.koma.filemanager.base.BasePresenter;
4 | import com.koma.filemanager.base.BaseView;
5 | import com.koma.filemanager.data.model.ZipFile;
6 |
7 | import java.util.ArrayList;
8 |
9 | /**
10 | * Created by koma on 12/12/16.
11 | */
12 |
13 | public interface FileCategoryContract {
14 | interface View extends BaseView {
15 | void refreshAdapter(ArrayList zipFiles);
16 |
17 | void showEmpty();
18 |
19 | void showLoadingView();
20 | }
21 |
22 | interface Presenter extends BasePresenter {
23 | void getZipFiles();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/filecategory/FileCategoryFragment.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.filecategory;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.koma.filemanager.R;
12 | import com.koma.filemanager.base.BaseFragment;
13 | import com.koma.filemanager.data.model.ZipFile;
14 | import com.koma.filemanager.util.LogUtils;
15 |
16 | import java.util.ArrayList;
17 |
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 |
21 | /**
22 | * Created by koma on 12/12/16.
23 | */
24 |
25 | public class FileCategoryFragment extends BaseFragment implements FileCategoryContract.View {
26 | private static final String TAG = "FileCategoryFragment";
27 | private FileCategoryContract.Presenter mPresenter;
28 | @BindView(R.id.recycler_view)
29 | RecyclerView mRecyclerView;
30 | private FileCategoryAdapter mAdapter;
31 | private ArrayList mData;
32 |
33 | public void onAttach(Context context) {
34 | super.onAttach(context);
35 | LogUtils.i(TAG, "onAttach");
36 | }
37 |
38 | public void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | LogUtils.i(TAG, "onCreate'");
41 | }
42 |
43 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
44 | View view = inflater.inflate(R.layout.recyclerview, container, false);
45 | ButterKnife.bind(this, view);
46 | mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
47 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
48 | linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
49 | mRecyclerView.setLayoutManager(linearLayoutManager);
50 | mData = new ArrayList<>();
51 | mAdapter = new FileCategoryAdapter(mContext, mData);
52 | mRecyclerView.setAdapter(mAdapter);
53 | return view;
54 | }
55 |
56 | public void onViewCreated(View view, Bundle savedInstanceState) {
57 | super.onViewCreated(view, savedInstanceState);
58 | LogUtils.i(TAG, "onViewCreated");
59 | }
60 |
61 | public void onDestroyView() {
62 | super.onDestroyView();
63 | LogUtils.i(TAG, "onDestroyView");
64 | if (mPresenter != null) {
65 | mPresenter.unSubscribe();
66 | }
67 | }
68 |
69 |
70 | @Override
71 | public void refreshAdapter(ArrayList zipFiles) {
72 | LogUtils.i(TAG, "refreshAdapter");
73 | if (mData != null) {
74 | mData.clear();
75 | } else {
76 | mData = new ArrayList<>();
77 | }
78 | mData.addAll(zipFiles);
79 | mAdapter.notifyDataSetChanged();
80 | }
81 |
82 | @Override
83 | public void showEmpty() {
84 | LogUtils.i(TAG, "showEmpty");
85 | }
86 |
87 | @Override
88 | public void showLoadingView() {
89 | LogUtils.i(TAG, "showLoadingView");
90 | }
91 |
92 | @Override
93 | public void setPresenter(FileCategoryContract.Presenter presenter) {
94 | mPresenter = presenter;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/filecategory/FileCategoryPresenter.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.filecategory;
2 |
3 | import com.koma.filemanager.data.FileRepository;
4 | import com.koma.filemanager.data.model.ZipFile;
5 | import com.koma.filemanager.util.LogUtils;
6 |
7 | import java.util.ArrayList;
8 |
9 | import rx.Subscriber;
10 | import rx.Subscription;
11 | import rx.android.schedulers.AndroidSchedulers;
12 | import rx.schedulers.Schedulers;
13 | import rx.subscriptions.CompositeSubscription;
14 |
15 | /**
16 | * Created by koma on 12/12/16.
17 | */
18 |
19 | public class FileCategoryPresenter implements FileCategoryContract.Presenter {
20 | private static final String TAG = "FileCategoryPresenter";
21 | private CompositeSubscription mSubscriptions;
22 | private FileRepository mRespository;
23 | private FileCategoryContract.View mView;
24 | private Subscription mZipFilesSubsription;
25 |
26 | public FileCategoryPresenter(FileCategoryContract.View view, FileRepository repository) {
27 | mView = view;
28 | mRespository = repository;
29 | mSubscriptions = new CompositeSubscription();
30 | mView.setPresenter(this);
31 | }
32 |
33 | private Subscriber> mZipSubsriber = new Subscriber>() {
34 | @Override
35 | public void onCompleted() {
36 | LogUtils.i(TAG, "onCompleted");
37 | }
38 |
39 | @Override
40 | public void onError(Throwable e) {
41 | LogUtils.i(TAG, "onError :" + e.toString());
42 | }
43 |
44 | @Override
45 | public void onNext(ArrayList zipFiles) {
46 | LogUtils.i(TAG, "onNext");
47 | if (mView != null) {
48 | if (zipFiles.size() == 0) {
49 | mView.showEmpty();
50 | } else {
51 | mView.refreshAdapter(zipFiles);
52 | }
53 | }
54 | }
55 | };
56 |
57 | @Override
58 | public void getZipFiles() {
59 | LogUtils.i(TAG, "getZipFiles");
60 | if (mSubscriptions != null) {
61 | mSubscriptions.remove(mZipSubsriber);
62 | }
63 | if (mRespository != null) {
64 | mZipFilesSubsription = mRespository.getZipFiles()
65 | .subscribeOn(Schedulers.io())
66 | .observeOn(AndroidSchedulers.mainThread())
67 | .subscribe(mZipSubsriber);
68 | }
69 | mSubscriptions.add(mZipFilesSubsription);
70 | }
71 |
72 | @Override
73 | public void subscribe() {
74 | LogUtils.i(TAG, "subsribe");
75 | getZipFiles();
76 | }
77 |
78 | @Override
79 | public void unSubscribe() {
80 | LogUtils.i(TAG, "unSubsribe");
81 | if (mSubscriptions != null) {
82 | mSubscriptions.clear();
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/fileview/FileViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.fileview;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.FragmentTransaction;
5 |
6 | import com.koma.filemanager.R;
7 | import com.koma.filemanager.base.BaseMenuActivity;
8 | import com.koma.filemanager.data.FileRepository;
9 | import com.koma.filemanager.helper.FileSortHelper;
10 | import com.koma.filemanager.helper.RxBus;
11 | import com.koma.filemanager.helper.event.SortEvent;
12 | import com.koma.filemanager.util.Constants;
13 | import com.koma.filemanager.util.LogUtils;
14 |
15 | /**
16 | * Created by koma on 11/30/16.
17 | */
18 |
19 | public class FileViewActivity extends BaseMenuActivity {
20 | private static final String TAG = "FileViewActivity";
21 | FileViewPresenter mPresenter;
22 | private String mPath;
23 |
24 | public void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | LogUtils.i(TAG, "onCreate");
27 | init();
28 | }
29 |
30 | private void init() {
31 | if (getIntent().getExtras() != null) {
32 | mPath = getIntent().getStringExtra(Constants.EXTRA_FILE_DIRECTORY);
33 | LogUtils.i(TAG, "init mPath : " + mPath);
34 | }
35 | FileViewFragment fileViewFragment = (FileViewFragment) getSupportFragmentManager().findFragmentById(R.id.content);
36 | if (fileViewFragment == null) {
37 | fileViewFragment = FileViewFragment.newInstance(mPath);
38 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
39 | transaction.replace(R.id.content, fileViewFragment).commit();
40 | }
41 | mPresenter = new FileViewPresenter(fileViewFragment, FileRepository.getInstance());
42 | }
43 |
44 | public String getPath() {
45 | return mPath;
46 | }
47 |
48 | @Override
49 | protected int getLayoutId() {
50 | return R.layout.common_layout;
51 | }
52 |
53 | @Override
54 | public void onStart() {
55 | super.onStart();
56 | LogUtils.i(TAG, "onStart");
57 | }
58 |
59 | @Override
60 | public void onResume() {
61 | super.onResume();
62 | LogUtils.i(TAG, "onResume");
63 | }
64 |
65 | @Override
66 | protected void sortByType() {
67 | LogUtils.i(TAG, "sortByType");
68 | RxBus.getInstance().post(new SortEvent(FileSortHelper.SortKey.type, FileSortHelper.SortMethod.asc));
69 | }
70 |
71 | @Override
72 | protected void sortByName() {
73 | LogUtils.i(TAG, "sortByName");
74 | RxBus.getInstance().post(new SortEvent(FileSortHelper.SortKey.name, FileSortHelper.SortMethod.asc));
75 | }
76 |
77 | @Override
78 | protected void sortBySize() {
79 | LogUtils.i(TAG, "sortBySize");
80 | RxBus.getInstance().post(new SortEvent(FileSortHelper.SortKey.size, FileSortHelper.SortMethod.asc));
81 | }
82 |
83 | @Override
84 | protected void sortByDate() {
85 | LogUtils.i(TAG, "sortByDate");
86 | RxBus.getInstance().post(new SortEvent(FileSortHelper.SortKey.date, FileSortHelper.SortMethod.asc));
87 | }
88 |
89 |
90 | @Override
91 | public void onPause() {
92 | super.onPause();
93 | LogUtils.i(TAG, "onPause");
94 | }
95 |
96 | @Override
97 | public void onStop() {
98 | super.onStop();
99 | LogUtils.i(TAG, "onStop");
100 | }
101 |
102 | @Override
103 | public void onDestroy() {
104 | super.onDestroy();
105 | LogUtils.i(TAG, "onDestroy");
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/fileview/FileViewContract.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.fileview;
2 |
3 | import com.koma.filemanager.base.BaseFile;
4 | import com.koma.filemanager.base.BasePresenter;
5 | import com.koma.filemanager.base.BaseView;
6 | import com.koma.filemanager.helper.event.SortEvent;
7 |
8 | import java.util.ArrayList;
9 |
10 | /**
11 | * Created by koma on 12/1/16.
12 | */
13 |
14 | public interface FileViewContract {
15 | interface View extends BaseView {
16 | void refreshAdapter(ArrayList files);
17 |
18 | void showLoadingView();
19 |
20 | void hideLoadingView();
21 |
22 | void showEmptyView();
23 |
24 | String getPath();
25 |
26 | void onSortSuccess();
27 | }
28 |
29 | interface Presenter extends BasePresenter {
30 | void getFiles(String path);
31 |
32 | void sortFiles(ArrayList files, SortEvent sortEvent);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/helper/FileCountHelper.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.helper;
2 |
3 |
4 | import java.io.File;
5 |
6 | import rx.Observable;
7 | import rx.Subscriber;
8 |
9 | /**
10 | * Created by koma on 12/2/16.
11 | */
12 |
13 | public class FileCountHelper {
14 | private static final String TAG = "FileCountHelper";
15 | private static FileCountHelper mHelper;
16 |
17 | private FileCountHelper() {
18 | }
19 |
20 | public synchronized static FileCountHelper getInstance() {
21 | if (mHelper == null) {
22 | mHelper = new FileCountHelper();
23 | }
24 | return mHelper;
25 | }
26 |
27 | public Observable getFileCount(final String fullPath) {
28 | return Observable.create(new Observable.OnSubscribe() {
29 | @Override
30 | public void call(Subscriber super Integer> subscriber) {
31 | File file = new File(fullPath);
32 | int filesCount = FileHelper.getSubFilesCount(file);
33 | subscriber.onNext(Integer.valueOf(filesCount));
34 | subscriber.onCompleted();
35 | }
36 | });
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/helper/FileSortHelper.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.helper;
2 |
3 | import com.koma.filemanager.base.BaseFile;
4 |
5 | import java.text.Collator;
6 | import java.util.Collections;
7 | import java.util.Comparator;
8 | import java.util.List;
9 |
10 | /**
11 | * Created by koma on 12/14/16.
12 | */
13 |
14 | public class FileSortHelper {
15 | public enum SortKey {
16 | type, name, size, date
17 | }
18 |
19 | public enum SortMethod {
20 | asc, desc
21 | }
22 |
23 | public static void sortBaseFile(List files, final SortKey sortKey,
24 | final SortMethod sortMethod) {
25 | Collections.sort(files, new Comparator() {
26 | @Override
27 | public int compare(BaseFile fileL, BaseFile fileR) {
28 | // 排序规则,文件夹放前面,文件放后面
29 | boolean isLhsDirectory = fileL.getIsDirectory();
30 | boolean isRhsDirectory = fileR.getIsDirectory();
31 | if (isLhsDirectory || isRhsDirectory) {
32 | if (isLhsDirectory && isRhsDirectory) {
33 | return doCompare(fileL, fileR, sortKey, sortMethod);
34 | }
35 | return (isLhsDirectory) ? -1 : 1;
36 | }
37 | return doCompare(fileL, fileR, sortKey, sortMethod);
38 | }
39 | });
40 | }
41 |
42 | public static int doCompare(final BaseFile file1, final BaseFile file2,
43 | SortKey sortKey,
44 | SortMethod sortMethod) {
45 | int sortFactor = 1;// 先确定是升序,还是降序
46 | if (sortMethod == SortMethod.desc) {
47 | sortFactor = -1;
48 | }
49 | if (sortKey == SortKey.name) {
50 | return Collator.getInstance(java.util.Locale.CHINA).compare(file1.getFileName(),
51 | file2.getFileName()) * sortFactor;
52 | }
53 | if (sortKey == SortKey.date) {
54 | return file1.getFileModifiedTime().compareTo(file2.getFileModifiedTime()) * sortFactor;
55 | }
56 | if (sortKey == SortKey.size) {
57 | return Long.compare(file1.getFileSize(), file2.getFileSize()) * sortFactor;
58 | }
59 | return file1.compareTo(file2);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/helper/ImageLoder.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.helper;
2 |
3 | /**
4 | * Created by koma on 12/2/16.
5 | */
6 |
7 | public class ImageLoder {
8 | public static void loadImage() {
9 |
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/helper/MeidaHelper.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.helper;
2 |
3 | import android.content.ContentUris;
4 | import android.net.Uri;
5 |
6 | /**
7 | * Created by koma on 12/5/16.
8 | */
9 |
10 | public class MeidaHelper {
11 | private static final String TAG = "MediaHelper";
12 | public static Uri getAlbumArtUri(long albumId) {
13 | return ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"), albumId);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/koma/filemanager/helper/RxBus.java:
--------------------------------------------------------------------------------
1 | package com.koma.filemanager.helper;
2 |
3 | import com.koma.filemanager.util.LogUtils;
4 |
5 | import rx.Observable;
6 | import rx.Subscriber;
7 | import rx.subjects.PublishSubject;
8 |
9 | /**
10 | * Created by koma on 12/14/16.
11 | */
12 |
13 | public class RxBus {
14 | private static final String TAG = "RxBus";
15 |
16 | private static volatile RxBus sInstance;
17 |
18 | public static RxBus getInstance() {
19 | if (sInstance == null) {
20 | synchronized (RxBus.class) {
21 | if (sInstance == null) {
22 | sInstance = new RxBus();
23 | }
24 | }
25 | }
26 | return sInstance;
27 | }
28 |
29 | /**
30 | * PublishSubject