Browse Source

Merge branch 'simple_cleanup' of https://github.com/tonymanou/Shelter

Peter Cai 4 months ago
parent
commit
bb2e425f06
Signed by: Peter Cai <[email protected]> GPG Key ID: 71F5FB4E4F3FD54F

+ 5
- 4
app/src/main/java/net/typeblog/shelter/services/FileShuttleService.java View File

@@ -26,6 +26,7 @@ import java.io.File;
26 26
 import java.io.FileNotFoundException;
27 27
 import java.io.FileOutputStream;
28 28
 import java.io.IOException;
29
+import java.io.Serializable;
29 30
 import java.util.ArrayList;
30 31
 import java.util.HashMap;
31 32
 import java.util.List;
@@ -46,9 +47,9 @@ public class FileShuttleService extends Service {
46 47
         }
47 48
 
48 49
         @Override
49
-        public List<Map> loadFiles(String path) {
50
+        public List<Map<String, Serializable>> loadFiles(String path) {
50 51
             resetSuicideTask();
51
-            ArrayList<Map> ret = new ArrayList<>();
52
+            ArrayList<Map<String, Serializable>> ret = new ArrayList<>();
52 53
             File f = new File(resolvePath(path));
53 54
             if (f.listFiles() != null) {
54 55
                 for (File child : f.listFiles()) {
@@ -59,10 +60,10 @@ public class FileShuttleService extends Service {
59 60
         }
60 61
 
61 62
         @Override
62
-        public Map loadFileMeta(String path) {
63
+        public Map<String, Serializable> loadFileMeta(String path) {
63 64
             resetSuicideTask();
64 65
             File f = new File(resolvePath(path));
65
-            HashMap<String, Object> map = new HashMap<>();
66
+            HashMap<String, Serializable> map = new HashMap<>();
66 67
             map.put(DocumentsContract.Document.COLUMN_DOCUMENT_ID, f.getAbsolutePath());
67 68
             map.put(DocumentsContract.Document.COLUMN_DISPLAY_NAME, f.getName());
68 69
             map.put(DocumentsContract.Document.COLUMN_SIZE, f.length());

+ 2
- 2
app/src/main/java/net/typeblog/shelter/services/FreezeService.java View File

@@ -50,10 +50,10 @@ public class FreezeService extends Service {
50 50
     }
51 51
 
52 52
     // An app being inactive for this amount of time will be frozen
53
-    private static long APP_INACTIVE_TIMEOUT = 1000;
53
+    private static final long APP_INACTIVE_TIMEOUT = 1000;
54 54
 
55 55
     // Notification ID
56
-    private static int NOTIFICATION_ID = 0xe49c0;
56
+    private static final int NOTIFICATION_ID = 0xe49c0;
57 57
 
58 58
     // The actual receiver of the screen-off event
59 59
     private BroadcastReceiver mLockReceiver = new BroadcastReceiver() {

+ 10
- 12
app/src/main/java/net/typeblog/shelter/ui/AppListAdapter.java View File

@@ -29,16 +29,14 @@ import java.util.stream.Collectors;
29 29
 
30 30
 public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHolder> {
31 31
     class ViewHolder extends RecyclerView.ViewHolder {
32
-        private ViewGroup mView;
33 32
         private ImageView mIcon;
34 33
         private TextView mTitle;
35 34
         private TextView mPackage;
36 35
         // This text view shows the order of all selected items
37 36
         private TextView mSelectOrder;
38 37
         int mIndex = -1;
39
-        ViewHolder(ViewGroup view) {
38
+        ViewHolder(View view) {
40 39
             super(view);
41
-            mView = view;
42 40
             mIcon = view.findViewById(R.id.list_app_icon);
43 41
             mTitle = view.findViewById(R.id.list_app_title);
44 42
             mPackage = view.findViewById(R.id.list_app_package);
@@ -57,7 +55,7 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
57 55
                 // pass the full info to it, since we can't be sure
58 56
                 // the index won't change
59 57
                 if (mContextMenuHandler != null) {
60
-                    mContextMenuHandler.showContextMenu(mList.get(mIndex), mView);
58
+                    mContextMenuHandler.showContextMenu(mList.get(mIndex), itemView);
61 59
                 }
62 60
             } else {
63 61
                 // In multi-select mode, single clicks just adds to the selection
@@ -91,7 +89,7 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
91 89
         void select() {
92 90
             mSelectedIndices.add(mIndex);
93 91
             mSelectOrder.clearAnimation();
94
-            mSelectOrder.startAnimation(AnimationUtils.loadAnimation(mView.getContext(), R.anim.scale_appear));
92
+            mSelectOrder.startAnimation(AnimationUtils.loadAnimation(itemView.getContext(), R.anim.scale_appear));
95 93
             showSelectOrder();
96 94
         }
97 95
 
@@ -100,7 +98,7 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
100 98
             mSelectedIndices.remove((Integer) mIndex);
101 99
             mSelectOrder.clearAnimation();
102 100
             setUnselectedBackground();
103
-            Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.scale_hide);
101
+            Animation anim = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.scale_hide);
104 102
             anim.setAnimationListener(new Animation.AnimationListener() {
105 103
                 @Override
106 104
                 public void onAnimationStart(Animation animation) {
@@ -132,11 +130,11 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
132 130
         // (not necessarily when the user clicked on it; the view might have been recycled)
133 131
         void showSelectOrder() {
134 132
             if (!mList.get(mIndex).isHidden()) {
135
-                mView.setBackgroundResource(R.color.selectedAppBackground);
133
+                itemView.setBackgroundResource(R.color.selectedAppBackground);
136 134
             } else {
137 135
                 // The app is both frozen and selected
138 136
                 // we use a blended color of the two for its background
139
-                mView.setBackgroundResource(R.color.selectedAndDisabledAppBackground);
137
+                itemView.setBackgroundResource(R.color.selectedAndDisabledAppBackground);
140 138
             }
141 139
             mSelectOrder.setVisibility(View.VISIBLE);
142 140
             mSelectOrder.setText(String.valueOf(mSelectedIndices.indexOf(mIndex) + 1));
@@ -151,9 +149,9 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
151 149
         // Set the background when not in the selected state
152 150
         void setUnselectedBackground() {
153 151
             if (!mList.get(mIndex).isHidden()) {
154
-                mView.setBackground(null);
152
+                itemView.setBackground(null);
155 153
             } else {
156
-                mView.setBackgroundResource(R.color.disabledAppBackground);
154
+                itemView.setBackgroundResource(R.color.disabledAppBackground);
157 155
             }
158 156
         }
159 157
 
@@ -327,8 +325,8 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
327 325
         if (mLabelDisabled == null) {
328 326
             mLabelDisabled = viewGroup.getContext().getString(R.string.list_item_disabled);
329 327
         }
330
-        LayoutInflater inflater = viewGroup.getContext().getSystemService(LayoutInflater.class);
331
-        ViewGroup view = (ViewGroup) inflater.inflate(R.layout.app_list_item, viewGroup, false);
328
+        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
329
+        View view = inflater.inflate(R.layout.app_list_item, viewGroup, false);
332 330
         ViewHolder vh = new ViewHolder(view);
333 331
         vh.setIndex(i);
334 332
         return vh;

+ 1
- 1
app/src/main/java/net/typeblog/shelter/ui/AppListFragment.java View File

@@ -98,7 +98,7 @@ public class AppListFragment extends BaseFragment {
98 98
         @Override
99 99
         public void onReceive(Context context, Intent intent) {
100 100
             String query = intent.getStringExtra("text");
101
-            if (query == "") {
101
+            if ("".equals(query)) {
102 102
                 // Consider empty query as null
103 103
                 query = null;
104 104
             }

+ 6
- 5
app/src/main/java/net/typeblog/shelter/util/CrossProfileDocumentsProvider.java View File

@@ -22,6 +22,7 @@ import net.typeblog.shelter.services.IFileShuttleService;
22 22
 import net.typeblog.shelter.services.IFileShuttleServiceCallback;
23 23
 import net.typeblog.shelter.ui.DummyActivity;
24 24
 
25
+import java.io.Serializable;
25 26
 import java.util.List;
26 27
 import java.util.Map;
27 28
 
@@ -50,7 +51,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
50 51
     // We just release the service when idle, thus enabling the
51 52
     // system to release memory
52 53
     private Runnable mReleaseServiceTask = this::releaseService;
53
-    private Object mLock = new Object();
54
+    private final Object mLock = new Object();
54 55
 
55 56
     private void doBindService() {
56 57
         // Call DummyActivity on the other side to bind the service for us
@@ -137,7 +138,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
137 138
     public Cursor queryDocument(String documentId, String[] projection) {
138 139
         ensureServiceBound();
139 140
         final MatrixCursor result = new MatrixCursor(projection == null ? DEFAULT_DOCUMENT_PROJECTION : projection);
140
-        Map<String, Object> fileInfo = null;
141
+        Map<String, Serializable> fileInfo;
141 142
         try {
142 143
             fileInfo = mService.loadFileMeta(documentId);
143 144
         } catch (RemoteException e) {
@@ -150,7 +151,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
150 151
     @Override
151 152
     public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) {
152 153
         ensureServiceBound();
153
-        List<Map<String, Object>> files = null;
154
+        List<Map<String, Serializable>> files;
154 155
         try {
155 156
             files = mService.loadFiles(parentDocumentId);
156 157
         } catch (RemoteException e) {
@@ -161,7 +162,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
161 162
         result.setNotificationUri(getContext().getContentResolver(),
162 163
                 DocumentsContract.buildDocumentUri(AUTHORITY, parentDocumentId));
163 164
 
164
-        for (Map<String, Object> file : files) {
165
+        for (Map<String, Serializable> file : files) {
165 166
             includeFile(result, file);
166 167
         }
167 168
         return result;
@@ -223,7 +224,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
223 224
         }
224 225
     }
225 226
 
226
-    private void includeFile(MatrixCursor cursor, Map<String, Object> fileInfo) {
227
+    private void includeFile(MatrixCursor cursor, Map<String, Serializable> fileInfo) {
227 228
         final MatrixCursor.RowBuilder row = cursor.newRow();
228 229
         for (String col : DEFAULT_DOCUMENT_PROJECTION) {
229 230
             row.add(col, fileInfo.get(col));

+ 1
- 1
app/src/main/java/net/typeblog/shelter/util/Utility.java View File

@@ -353,7 +353,7 @@ public class Utility {
353 353
     public static String getFileExtension(String filePath) {
354 354
         int index = filePath.lastIndexOf(".");
355 355
         if (index > 0) {
356
-            return filePath.substring(index + 1, filePath.length());
356
+            return filePath.substring(index + 1);
357 357
         } else {
358 358
             return null;
359 359
         }

Loading…
Cancel
Save