2013-12-26 12:43:37 +01:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2013-12-26 12:43:37 +01:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2017-03-31 01:58:05 +02:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
2013-12-26 12:43:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2013-12-26 12:43:37 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.content.res.Configuration;
|
2013-12-26 12:43:37 +01:00
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.StatFs;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.view.ViewTreeObserver;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.widget.FrameLayout;
|
2013-12-26 12:43:37 +01:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2015-08-13 11:23:31 +02:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.BuildVars;
|
2013-12-26 12:43:37 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2013-12-26 12:43:37 +01:00
|
|
|
import org.telegram.messenger.R;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.support.widget.LinearLayoutManager;
|
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2015-10-29 18:10:07 +01:00
|
|
|
import org.telegram.ui.ActionBar.BackDrawable;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Cells.GraySectionCell;
|
2015-02-01 19:51:02 +01:00
|
|
|
import org.telegram.ui.Cells.SharedDocumentCell;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.EmptyTextProgressView;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2015-10-29 18:10:07 +01:00
|
|
|
import org.telegram.ui.Components.NumberTextView;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2013-12-26 12:43:37 +01:00
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
2017-03-31 01:58:05 +02:00
|
|
|
import java.util.Collections;
|
2013-12-26 12:43:37 +01:00
|
|
|
import java.util.HashMap;
|
2015-08-13 11:23:31 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.StringTokenizer;
|
2013-12-26 12:43:37 +01:00
|
|
|
|
|
|
|
public class DocumentSelectActivity extends BaseFragment {
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface DocumentSelectActivityDelegate {
|
|
|
|
void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files);
|
|
|
|
void startDocumentSelectActivity();
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private RecyclerListView listView;
|
2013-12-26 12:43:37 +01:00
|
|
|
private ListAdapter listAdapter;
|
2015-10-29 18:10:07 +01:00
|
|
|
private NumberTextView selectedMessagesCountTextView;
|
2017-03-31 01:58:05 +02:00
|
|
|
private EmptyTextProgressView emptyView;
|
|
|
|
private LinearLayoutManager layoutManager;
|
2014-11-24 15:14:40 +01:00
|
|
|
|
|
|
|
private File currentDir;
|
2015-02-01 19:51:02 +01:00
|
|
|
private ArrayList<ListItem> items = new ArrayList<>();
|
2013-12-26 12:43:37 +01:00
|
|
|
private boolean receiverRegistered = false;
|
2015-02-01 19:51:02 +01:00
|
|
|
private ArrayList<HistoryEntry> history = new ArrayList<>();
|
2015-02-26 02:32:51 +01:00
|
|
|
private long sizeLimit = 1024 * 1024 * 1536;
|
2014-06-04 01:31:48 +02:00
|
|
|
private DocumentSelectActivityDelegate delegate;
|
2015-02-01 19:51:02 +01:00
|
|
|
private HashMap<String, ListItem> selectedFiles = new HashMap<>();
|
|
|
|
private ArrayList<View> actionModeViews = new ArrayList<>();
|
2014-11-24 15:14:40 +01:00
|
|
|
private boolean scrolling;
|
2017-03-31 01:58:05 +02:00
|
|
|
private ArrayList<ListItem> recentItems = new ArrayList<>();
|
2018-07-30 04:07:02 +02:00
|
|
|
private int maxSelectedFiles = -1;
|
|
|
|
private boolean canSelectOnlyImageFiles;
|
2014-11-24 15:14:40 +01:00
|
|
|
|
|
|
|
private final static int done = 3;
|
2013-12-26 12:43:37 +01:00
|
|
|
|
|
|
|
private class ListItem {
|
|
|
|
int icon;
|
|
|
|
String title;
|
|
|
|
String subtitle = "";
|
|
|
|
String ext = "";
|
|
|
|
String thumb;
|
|
|
|
File file;
|
2017-03-31 01:58:05 +02:00
|
|
|
long date;
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private class HistoryEntry {
|
|
|
|
int scrollItem, scrollOffset;
|
|
|
|
File dir;
|
|
|
|
String title;
|
|
|
|
}
|
|
|
|
|
|
|
|
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context arg0, Intent intent) {
|
2018-08-27 10:33:11 +02:00
|
|
|
Runnable r = () -> {
|
|
|
|
try {
|
|
|
|
if (currentDir == null) {
|
|
|
|
listRoots();
|
|
|
|
} else {
|
|
|
|
listFiles(currentDir);
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
if (Intent.ACTION_MEDIA_UNMOUNTED.equals(intent.getAction())) {
|
|
|
|
listView.postDelayed(r, 1000);
|
|
|
|
} else {
|
|
|
|
r.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
loadRecentFiles();
|
|
|
|
return super.onFragmentCreate();
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:43:37 +01:00
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
2014-02-04 19:36:55 +01:00
|
|
|
try {
|
|
|
|
if (receiverRegistered) {
|
2015-08-13 11:23:31 +02:00
|
|
|
ApplicationLoader.applicationContext.unregisterReceiver(receiver);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
super.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2013-12-26 12:43:37 +01:00
|
|
|
if (!receiverRegistered) {
|
|
|
|
receiverRegistered = true;
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_CHECKING);
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_EJECT);
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_NOFS);
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_REMOVED);
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_SHARED);
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
|
|
|
|
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
|
|
|
|
filter.addDataScheme("file");
|
2015-08-13 11:23:31 +02:00
|
|
|
ApplicationLoader.applicationContext.registerReceiver(receiver, filter);
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
actionBar.setBackButtonDrawable(new BackDrawable(false));
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setAllowOverlayTitle(true);
|
|
|
|
actionBar.setTitle(LocaleController.getString("SelectFile", R.string.SelectFile));
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
2015-10-29 18:10:07 +01:00
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
selectedFiles.clear();
|
|
|
|
actionBar.hideActionMode();
|
2017-03-31 01:58:05 +02:00
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = listView.getChildAt(a);
|
|
|
|
if (child instanceof SharedDocumentCell) {
|
|
|
|
((SharedDocumentCell) child).setChecked(false, true);
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
} else {
|
|
|
|
finishFragment();
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (id == done) {
|
|
|
|
if (delegate != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
ArrayList<String> files = new ArrayList<>(selectedFiles.keySet());
|
2015-04-09 20:00:14 +02:00
|
|
|
delegate.didSelectFiles(DocumentSelectActivity.this, files);
|
2017-03-31 01:58:05 +02:00
|
|
|
for (ListItem item : selectedFiles.values()) {
|
|
|
|
item.date = System.currentTimeMillis();
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
selectedFiles.clear();
|
|
|
|
actionModeViews.clear();
|
2014-11-24 15:14:40 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
final ActionBarMenu actionMode = actionBar.createActionMode();
|
2014-11-24 15:14:40 +01:00
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
|
2015-04-09 20:00:14 +02:00
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
|
|
|
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2017-03-31 01:58:05 +02:00
|
|
|
selectedMessagesCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarActionModeDefaultIcon));
|
2018-08-27 10:33:11 +02:00
|
|
|
selectedMessagesCountTextView.setOnTouchListener((v, event) -> true);
|
2015-10-29 18:10:07 +01:00
|
|
|
actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));
|
2014-11-24 15:14:40 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
actionModeViews.add(actionMode.addItemWithWidth(done, R.drawable.ic_ab_done, AndroidUtilities.dp(54)));
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
fragmentView = new FrameLayout(context);
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
2014-11-24 15:14:40 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
emptyView = new EmptyTextProgressView(context);
|
|
|
|
emptyView.showTextView();
|
|
|
|
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2014-11-24 15:14:40 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
listView = new RecyclerListView(context);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
listView.setAdapter(listAdapter = new ListAdapter(context));
|
|
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
scrolling = newState != RecyclerView.SCROLL_STATE_IDLE;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2014-11-24 15:14:40 +01:00
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
listView.setOnItemLongClickListener((view, position) -> {
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ListItem item = listAdapter.getItem(position);
|
|
|
|
if (item == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
File file = item.file;
|
|
|
|
if (file != null && !file.isDirectory()) {
|
|
|
|
if (!file.canRead()) {
|
|
|
|
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
|
2017-03-31 01:58:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
if (canSelectOnlyImageFiles && item.thumb == null) {
|
|
|
|
showErrorBox(LocaleController.formatString("PassportUploadNotImage", R.string.PassportUploadNotImage));
|
2015-04-09 20:00:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
if (sizeLimit != 0) {
|
|
|
|
if (file.length() > sizeLimit) {
|
|
|
|
showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, AndroidUtilities.formatFileSize(sizeLimit)));
|
2018-07-30 04:07:02 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-11-24 15:14:40 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
if (maxSelectedFiles >= 0 && selectedFiles.size() >= maxSelectedFiles) {
|
|
|
|
showErrorBox(LocaleController.formatString("PassportUploadMaxReached", R.string.PassportUploadMaxReached, LocaleController.formatPluralString("Files", maxSelectedFiles)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (file.length() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
selectedFiles.put(file.toString(), item);
|
|
|
|
selectedMessagesCountTextView.setNumber(1, false);
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
ArrayList<Animator> animators = new ArrayList<>();
|
|
|
|
for (int a = 0; a < actionModeViews.size(); a++) {
|
|
|
|
View view2 = actionModeViews.get(a);
|
|
|
|
AndroidUtilities.clearDrawableAnimation(view2);
|
|
|
|
animators.add(ObjectAnimator.ofFloat(view2, "scaleY", 0.1f, 1.0f));
|
|
|
|
}
|
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
animatorSet.setDuration(250);
|
|
|
|
animatorSet.start();
|
|
|
|
scrolling = false;
|
|
|
|
if (view instanceof SharedDocumentCell) {
|
|
|
|
((SharedDocumentCell) view).setChecked(true, true);
|
|
|
|
}
|
|
|
|
actionBar.showActionMode();
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
return true;
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
2014-11-24 15:14:40 +01:00
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
listView.setOnItemClickListener((view, position) -> {
|
|
|
|
ListItem item = listAdapter.getItem(position);
|
|
|
|
if (item == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
File file = item.file;
|
|
|
|
if (file == null) {
|
|
|
|
if (item.icon == R.drawable.ic_storage_gallery) {
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.startDocumentSelectActivity();
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
finishFragment(false);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2018-08-27 10:33:11 +02:00
|
|
|
HistoryEntry he = history.remove(history.size() - 1);
|
|
|
|
actionBar.setTitle(he.title);
|
|
|
|
if (he.dir != null) {
|
|
|
|
listFiles(he.dir);
|
|
|
|
} else {
|
|
|
|
listRoots();
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
layoutManager.scrollToPositionWithOffset(he.scrollItem, he.scrollOffset);
|
|
|
|
}
|
|
|
|
} else if (file.isDirectory()) {
|
|
|
|
HistoryEntry he = new HistoryEntry();
|
|
|
|
he.scrollItem = layoutManager.findLastVisibleItemPosition();
|
|
|
|
View topView = layoutManager.findViewByPosition(he.scrollItem);
|
|
|
|
if (topView != null) {
|
|
|
|
he.scrollOffset = topView.getTop();
|
|
|
|
}
|
|
|
|
he.dir = currentDir;
|
|
|
|
he.title = actionBar.getTitle();
|
|
|
|
history.add(he);
|
|
|
|
if (!listFiles(file)) {
|
|
|
|
history.remove(he);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
actionBar.setTitle(item.title);
|
|
|
|
} else {
|
|
|
|
if (!file.canRead()) {
|
|
|
|
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
|
|
|
|
file = new File("/mnt/sdcard");
|
|
|
|
}
|
|
|
|
if (canSelectOnlyImageFiles && item.thumb == null) {
|
|
|
|
showErrorBox(LocaleController.formatString("PassportUploadNotImage", R.string.PassportUploadNotImage));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sizeLimit != 0) {
|
|
|
|
if (file.length() > sizeLimit) {
|
|
|
|
showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, AndroidUtilities.formatFileSize(sizeLimit)));
|
2018-07-30 04:07:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
if (file.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
if (selectedFiles.containsKey(file.toString())) {
|
|
|
|
selectedFiles.remove(file.toString());
|
|
|
|
} else {
|
|
|
|
if (maxSelectedFiles >= 0 && selectedFiles.size() >= maxSelectedFiles) {
|
|
|
|
showErrorBox(LocaleController.formatString("PassportUploadMaxReached", R.string.PassportUploadMaxReached, LocaleController.formatPluralString("Files", maxSelectedFiles)));
|
2013-12-26 12:43:37 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
selectedFiles.put(file.toString(), item);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
if (selectedFiles.isEmpty()) {
|
|
|
|
actionBar.hideActionMode();
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2018-08-27 10:33:11 +02:00
|
|
|
selectedMessagesCountTextView.setNumber(selectedFiles.size(), true);
|
|
|
|
}
|
|
|
|
scrolling = false;
|
|
|
|
if (view instanceof SharedDocumentCell) {
|
|
|
|
((SharedDocumentCell) view).setChecked(selectedFiles.containsKey(item.file.toString()), true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (delegate != null) {
|
|
|
|
ArrayList<String> files = new ArrayList<>();
|
|
|
|
files.add(file.getAbsolutePath());
|
|
|
|
delegate.didSelectFiles(DocumentSelectActivity.this, files);
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listRoots();
|
|
|
|
|
2013-12-26 12:43:37 +01:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void setMaxSelectedFiles(int value) {
|
|
|
|
maxSelectedFiles = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCanSelectOnlyImageFiles(boolean value) {
|
|
|
|
canSelectOnlyImageFiles = true;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public void loadRecentFiles() {
|
|
|
|
try {
|
|
|
|
File[] files = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).listFiles();
|
|
|
|
for (int a = 0; a < files.length; a++) {
|
|
|
|
File file = files[a];
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ListItem item = new ListItem();
|
|
|
|
item.title = file.getName();
|
|
|
|
item.file = file;
|
|
|
|
String fname = file.getName();
|
|
|
|
String[] sp = fname.split("\\.");
|
|
|
|
item.ext = sp.length > 1 ? sp[sp.length - 1] : "?";
|
|
|
|
item.subtitle = AndroidUtilities.formatFileSize(file.length());
|
|
|
|
fname = fname.toLowerCase();
|
|
|
|
if (fname.endsWith(".jpg") || fname.endsWith(".png") || fname.endsWith(".gif") || fname.endsWith(".jpeg")) {
|
|
|
|
item.thumb = file.getAbsolutePath();
|
|
|
|
}
|
|
|
|
recentItems.add(item);
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
Collections.sort(recentItems, (o1, o2) -> {
|
|
|
|
long lm = o1.file.lastModified();
|
|
|
|
long rm = o2.file.lastModified();
|
|
|
|
if (lm == rm) {
|
|
|
|
return 0;
|
|
|
|
} else if (lm > rm) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 1;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:43:37 +01:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 18:00:42 +02:00
|
|
|
super.onResume();
|
2014-06-04 01:31:48 +02:00
|
|
|
if (listAdapter != null) {
|
2013-12-26 12:43:37 +01:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
fixLayoutInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
if (listView != null) {
|
|
|
|
ViewTreeObserver obs = listView.getViewTreeObserver();
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
listView.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
fixLayoutInternal();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayoutInternal() {
|
|
|
|
if (selectedMessagesCountTextView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
|
|
|
} else {
|
|
|
|
selectedMessagesCountTextView.setTextSize(20);
|
|
|
|
}
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBackPressed() {
|
2014-09-30 00:48:11 +02:00
|
|
|
if (history.size() > 0) {
|
2013-12-26 12:43:37 +01:00
|
|
|
HistoryEntry he = history.remove(history.size() - 1);
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.setTitle(he.title);
|
2013-12-26 12:43:37 +01:00
|
|
|
if (he.dir != null) {
|
|
|
|
listFiles(he.dir);
|
|
|
|
} else {
|
|
|
|
listRoots();
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
layoutManager.scrollToPositionWithOffset(he.scrollItem, he.scrollOffset);
|
2013-12-26 12:43:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public void setDelegate(DocumentSelectActivityDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:43:37 +01:00
|
|
|
private boolean listFiles(File dir) {
|
|
|
|
if (!dir.canRead()) {
|
|
|
|
if (dir.getAbsolutePath().startsWith(Environment.getExternalStorageDirectory().toString())
|
|
|
|
|| dir.getAbsolutePath().startsWith("/sdcard")
|
|
|
|
|| dir.getAbsolutePath().startsWith("/mnt/sdcard")) {
|
|
|
|
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
|
|
|
|
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
|
|
|
|
currentDir = dir;
|
|
|
|
items.clear();
|
|
|
|
String state = Environment.getExternalStorageState();
|
2014-09-30 00:48:11 +02:00
|
|
|
if (Environment.MEDIA_SHARED.equals(state)) {
|
2014-03-22 23:31:55 +01:00
|
|
|
emptyView.setText(LocaleController.getString("UsbActive", R.string.UsbActive));
|
2013-12-26 12:43:37 +01:00
|
|
|
} else {
|
2014-03-22 23:31:55 +01:00
|
|
|
emptyView.setText(LocaleController.getString("NotMounted", R.string.NotMounted));
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
AndroidUtilities.clearDrawableAnimation(listView);
|
2014-11-24 15:14:40 +01:00
|
|
|
scrolling = true;
|
2013-12-26 12:43:37 +01:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
|
2013-12-26 12:43:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
File[] files;
|
2013-12-26 12:43:37 +01:00
|
|
|
try {
|
|
|
|
files = dir.listFiles();
|
|
|
|
} catch(Exception e) {
|
|
|
|
showErrorBox(e.getLocalizedMessage());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (files == null) {
|
2014-06-04 01:31:48 +02:00
|
|
|
showErrorBox(LocaleController.getString("UnknownError", R.string.UnknownError));
|
2013-12-26 12:43:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
currentDir = dir;
|
|
|
|
items.clear();
|
2018-08-27 10:33:11 +02:00
|
|
|
Arrays.sort(files, (lhs, rhs) -> {
|
|
|
|
if (lhs.isDirectory() != rhs.isDirectory()) {
|
|
|
|
return lhs.isDirectory() ? -1 : 1;
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
return lhs.getName().compareToIgnoreCase(rhs.getName());
|
|
|
|
/*long lm = lhs.lastModified();
|
|
|
|
long rm = lhs.lastModified();
|
|
|
|
if (lm == rm) {
|
|
|
|
return 0;
|
|
|
|
} else if (lm > rm) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}*/
|
2013-12-26 12:43:37 +01:00
|
|
|
});
|
2016-04-22 15:49:00 +02:00
|
|
|
for (int a = 0; a < files.length; a++) {
|
|
|
|
File file = files[a];
|
|
|
|
if (file.getName().indexOf('.') == 0) {
|
2013-12-26 12:43:37 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ListItem item = new ListItem();
|
|
|
|
item.title = file.getName();
|
|
|
|
item.file = file;
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
item.icon = R.drawable.ic_directory;
|
2014-11-17 03:44:57 +01:00
|
|
|
item.subtitle = LocaleController.getString("Folder", R.string.Folder);
|
2013-12-26 12:43:37 +01:00
|
|
|
} else {
|
|
|
|
String fname = file.getName();
|
|
|
|
String[] sp = fname.split("\\.");
|
|
|
|
item.ext = sp.length > 1 ? sp[sp.length - 1] : "?";
|
2015-05-21 23:27:27 +02:00
|
|
|
item.subtitle = AndroidUtilities.formatFileSize(file.length());
|
2013-12-26 12:43:37 +01:00
|
|
|
fname = fname.toLowerCase();
|
|
|
|
if (fname.endsWith(".jpg") || fname.endsWith(".png") || fname.endsWith(".gif") || fname.endsWith(".jpeg")) {
|
|
|
|
item.thumb = file.getAbsolutePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
items.add(item);
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
ListItem item = new ListItem();
|
|
|
|
item.title = "..";
|
2015-02-01 19:51:02 +01:00
|
|
|
if (history.size() > 0) {
|
|
|
|
HistoryEntry entry = history.get(history.size() - 1);
|
|
|
|
if (entry.dir == null) {
|
|
|
|
item.subtitle = LocaleController.getString("Folder", R.string.Folder);
|
|
|
|
} else {
|
|
|
|
item.subtitle = entry.dir.toString();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
item.subtitle = LocaleController.getString("Folder", R.string.Folder);
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
item.icon = R.drawable.ic_directory;
|
|
|
|
item.file = null;
|
|
|
|
items.add(0, item);
|
2014-11-17 03:44:57 +01:00
|
|
|
AndroidUtilities.clearDrawableAnimation(listView);
|
2014-11-24 15:14:40 +01:00
|
|
|
scrolling = true;
|
2013-12-26 12:43:37 +01:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-14 10:36:01 +02:00
|
|
|
private void showErrorBox(String error) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
new AlertDialog.Builder(getParentActivity()).setTitle(LocaleController.getString("AppName", R.string.AppName)).setMessage(error).setPositiveButton(LocaleController.getString("OK", R.string.OK), null).show();
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
@SuppressLint("NewApi")
|
2013-12-26 12:43:37 +01:00
|
|
|
private void listRoots() {
|
|
|
|
currentDir = null;
|
|
|
|
items.clear();
|
2015-08-13 11:23:31 +02:00
|
|
|
|
|
|
|
HashSet<String> paths = new HashSet<>();
|
|
|
|
String defaultPath = Environment.getExternalStorageDirectory().getPath();
|
2016-06-24 12:27:15 +02:00
|
|
|
boolean isDefaultPathRemovable = Environment.isExternalStorageRemovable();
|
2015-08-13 11:23:31 +02:00
|
|
|
String defaultPathState = Environment.getExternalStorageState();
|
|
|
|
if (defaultPathState.equals(Environment.MEDIA_MOUNTED) || defaultPathState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
|
|
|
|
ListItem ext = new ListItem();
|
2016-04-22 15:49:00 +02:00
|
|
|
if (Environment.isExternalStorageRemovable()) {
|
2015-08-13 11:23:31 +02:00
|
|
|
ext.title = LocaleController.getString("SdCard", R.string.SdCard);
|
|
|
|
ext.icon = R.drawable.ic_external_storage;
|
|
|
|
} else {
|
|
|
|
ext.title = LocaleController.getString("InternalStorage", R.string.InternalStorage);
|
|
|
|
ext.icon = R.drawable.ic_storage;
|
|
|
|
}
|
|
|
|
ext.subtitle = getRootSubtitle(defaultPath);
|
|
|
|
ext.file = Environment.getExternalStorageDirectory();
|
|
|
|
items.add(ext);
|
|
|
|
paths.add(defaultPath);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
|
|
|
BufferedReader bufferedReader = null;
|
2013-12-26 12:43:37 +01:00
|
|
|
try {
|
2015-08-13 11:23:31 +02:00
|
|
|
bufferedReader = new BufferedReader(new FileReader("/proc/mounts"));
|
2013-12-26 12:43:37 +01:00
|
|
|
String line;
|
2015-08-13 11:23:31 +02:00
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
if (line.contains("vfat") || line.contains("/mnt")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d(line);
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
StringTokenizer tokens = new StringTokenizer(line, " ");
|
|
|
|
String unused = tokens.nextToken();
|
|
|
|
String path = tokens.nextToken();
|
|
|
|
if (paths.contains(path)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (line.contains("/dev/block/vold")) {
|
|
|
|
if (!line.contains("/mnt/secure") && !line.contains("/mnt/asec") && !line.contains("/mnt/obb") && !line.contains("/dev/mapper") && !line.contains("tmpfs")) {
|
|
|
|
if (!new File(path).isDirectory()) {
|
|
|
|
int index = path.lastIndexOf('/');
|
|
|
|
if (index != -1) {
|
|
|
|
String newPath = "/storage/" + path.substring(index + 1);
|
|
|
|
if (new File(newPath).isDirectory()) {
|
|
|
|
path = newPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
paths.add(path);
|
|
|
|
try {
|
|
|
|
ListItem item = new ListItem();
|
|
|
|
if (path.toLowerCase().contains("sd")) {
|
|
|
|
item.title = LocaleController.getString("SdCard", R.string.SdCard);
|
|
|
|
} else {
|
|
|
|
item.title = LocaleController.getString("ExternalStorage", R.string.ExternalStorage);
|
|
|
|
}
|
|
|
|
item.icon = R.drawable.ic_external_storage;
|
|
|
|
item.subtitle = getRootSubtitle(path);
|
|
|
|
item.file = new File(path);
|
|
|
|
items.add(item);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-08-13 11:23:31 +02:00
|
|
|
} finally {
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
try {
|
|
|
|
bufferedReader.close();
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
ListItem fs = new ListItem();
|
|
|
|
fs.title = "/";
|
2014-03-22 23:31:55 +01:00
|
|
|
fs.subtitle = LocaleController.getString("SystemRoot", R.string.SystemRoot);
|
2013-12-26 12:43:37 +01:00
|
|
|
fs.icon = R.drawable.ic_directory;
|
|
|
|
fs.file = new File("/");
|
|
|
|
items.add(fs);
|
2014-09-30 00:48:11 +02:00
|
|
|
|
|
|
|
try {
|
2014-10-07 22:14:27 +02:00
|
|
|
File telegramPath = new File(Environment.getExternalStorageDirectory(), "Telegram");
|
2014-09-30 00:48:11 +02:00
|
|
|
if (telegramPath.exists()) {
|
|
|
|
fs = new ListItem();
|
2014-10-07 22:14:27 +02:00
|
|
|
fs.title = "Telegram";
|
2014-09-30 00:48:11 +02:00
|
|
|
fs.subtitle = telegramPath.toString();
|
|
|
|
fs.icon = R.drawable.ic_directory;
|
|
|
|
fs.file = telegramPath;
|
|
|
|
items.add(fs);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
fs = new ListItem();
|
|
|
|
fs.title = LocaleController.getString("Gallery", R.string.Gallery);
|
|
|
|
fs.subtitle = LocaleController.getString("GalleryInfo", R.string.GalleryInfo);
|
|
|
|
fs.icon = R.drawable.ic_storage_gallery;
|
|
|
|
fs.file = null;
|
|
|
|
items.add(fs);
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
AndroidUtilities.clearDrawableAnimation(listView);
|
2014-11-24 15:14:40 +01:00
|
|
|
scrolling = true;
|
2013-12-26 12:43:37 +01:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2014-09-30 00:48:11 +02:00
|
|
|
private String getRootSubtitle(String path) {
|
2015-08-13 11:23:31 +02:00
|
|
|
try {
|
|
|
|
StatFs stat = new StatFs(path);
|
|
|
|
long total = (long)stat.getBlockCount() * (long)stat.getBlockSize();
|
|
|
|
long free = (long)stat.getAvailableBlocks() * (long)stat.getBlockSize();
|
|
|
|
if (total == 0) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return LocaleController.formatString("FreeOfTotal", R.string.FreeOfTotal, AndroidUtilities.formatFileSize(free), AndroidUtilities.formatFileSize(total));
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
return path;
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
|
2013-12-26 12:43:37 +01:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return holder.getItemViewType() != 0;
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public int getItemCount() {
|
|
|
|
int count = items.size();
|
|
|
|
if (history.isEmpty() && !recentItems.isEmpty()) {
|
|
|
|
count += recentItems.size() + 1;
|
|
|
|
}
|
|
|
|
return count;
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public ListItem getItem(int position) {
|
|
|
|
if (position < items.size()) {
|
|
|
|
return items.get(position);
|
|
|
|
} else if (history.isEmpty() && !recentItems.isEmpty() && position != items.size()) {
|
|
|
|
position -= items.size() + 1;
|
|
|
|
if (position < recentItems.size()) {
|
|
|
|
return recentItems.get(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
return getItem(position) != null ? 1 : 0;
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
|
|
|
view = new GraySectionCell(mContext);
|
|
|
|
((GraySectionCell) view).setText(LocaleController.getString("Recent", R.string.Recent).toUpperCase());
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
default:
|
|
|
|
view = new SharedDocumentCell(mContext);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return new RecyclerListView.Holder(view);
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
if (holder.getItemViewType() == 1) {
|
|
|
|
ListItem item = getItem(position);
|
|
|
|
SharedDocumentCell documentCell = (SharedDocumentCell) holder.itemView;
|
|
|
|
if (item.icon != 0) {
|
|
|
|
documentCell.setTextAndValueAndTypeAndThumb(item.title, item.subtitle, null, null, item.icon);
|
|
|
|
} else {
|
|
|
|
String type = item.ext.toUpperCase().substring(0, Math.min(item.ext.length(), 4));
|
|
|
|
documentCell.setTextAndValueAndTypeAndThumb(item.title, item.subtitle, type, item.thumb, 0);
|
|
|
|
}
|
|
|
|
if (item.file != null && actionBar.isActionModeShowed()) {
|
|
|
|
documentCell.setChecked(selectedFiles.containsKey(item.file.toString()), !scrolling);
|
|
|
|
} else {
|
|
|
|
documentCell.setChecked(false, !scrolling);
|
|
|
|
}
|
2014-11-24 15:14:40 +01:00
|
|
|
}
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ThemeDescription[] getThemeDescriptions() {
|
|
|
|
return new ThemeDescription[]{
|
|
|
|
new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite),
|
|
|
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector),
|
|
|
|
|
|
|
|
new ThemeDescription(emptyView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_emptyListPlaceholder),
|
|
|
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultIcon),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_BACKGROUND, null, null, null, null, Theme.key_actionBarActionModeDefault),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_TOPBACKGROUND, null, null, null, null, Theme.key_actionBarActionModeDefaultTop),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultSelector),
|
|
|
|
|
|
|
|
new ThemeDescription(selectedMessagesCountTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultIcon),
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
new ThemeDescription(listView, 0, new Class[]{GraySectionCell.class}, new String[]{"textView"}, null, null, null, Theme.key_graySectionText),
|
2017-03-31 01:58:05 +02:00
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{GraySectionCell.class}, null, null, null, Theme.key_graySection),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"nameTextView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"dateTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOX, new Class[]{SharedDocumentCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_checkbox),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOXCHECK, new Class[]{SharedDocumentCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_checkboxCheck),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_IMAGECOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"thumbImageView"}, null, null, null, Theme.key_files_folderIcon),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_IMAGECOLOR | ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{SharedDocumentCell.class}, new String[]{"thumbImageView"}, null, null, null, Theme.key_files_folderIconBackground),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"extTextView"}, null, null, null, Theme.key_files_iconText),
|
|
|
|
};
|
|
|
|
}
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|