Skip to content

Commit 8e13600

Browse files
committed
Moved ReFile list to owm CDN
1 parent c39d15c commit 8e13600

File tree

6 files changed

+101
-77
lines changed

6 files changed

+101
-77
lines changed

.idea/deploymentTargetSelector.xml

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ android {
2525
applicationId "com.noti.main"
2626
minSdkVersion 23
2727
targetSdkVersion 34
28-
versionCode 1012202
29-
versionName "1.22.2"
28+
versionCode 1012203
29+
versionName "1.22.3"
3030

3131
multiDexEnabled true
3232
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
@@ -79,8 +79,8 @@ dependencies {
7979
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
8080
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
8181

82-
implementation 'androidx.navigation:navigation-fragment-ktx:2.8.2'
83-
implementation 'androidx.navigation:navigation-ui-ktx:2.8.2'
82+
implementation 'androidx.navigation:navigation-fragment-ktx:2.8.3'
83+
implementation 'androidx.navigation:navigation-ui-ktx:2.8.3'
8484
implementation "androidx.documentfile:documentfile:1.0.1"
8585
implementation 'androidx.core:core-ktx:1.13.1'
8686
implementation 'androidx.palette:palette-ktx:1.0.0'
@@ -97,7 +97,7 @@ dependencies {
9797
implementation 'com.google.android.gms:play-services-maps:19.0.0'
9898
implementation 'com.google.auth:google-auth-library-oauth2-http:1.24.1'
9999

100-
implementation platform('com.google.firebase:firebase-bom:33.4.0')
100+
implementation platform('com.google.firebase:firebase-bom:33.5.1')
101101
implementation 'com.google.firebase:firebase-auth'
102102
implementation 'com.google.firebase:firebase-messaging'
103103
implementation 'com.google.firebase:firebase-analytics'

app/src/main/java/com/noti/main/service/backend/PacketConst.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
public class PacketConst {
55

66
public final static String SERVICE_TYPE_LIVE_NOTIFICATION = "type_live_notification";
7-
public final static String SERVICE_TYPE_FILE_TRANSFER = "type_file_transfer";
87
public final static String SERVICE_TYPE_IMAGE_CACHE = "type_image_cache";
98
public final static String SERVICE_TYPE_PACKET_PROXY = "type_packet_proxy";
9+
public final static String SERVICE_TYPE_FILE_TRANSFER = "type_file_transfer";
10+
public final static String SERVICE_TYPE_FILE_LIST = "type_file_list";
1011
public final static String SERVICE_TYPE_PACKET_BONDING = "type_packet_bonding";
1112
public final static String SERVICE_TYPE_PING_SERVER = "type_ping";
1213

1314
public final static String REQUEST_POST_SHORT_TERM_DATA = "request_post_short_term_data";
1415
public final static String REQUEST_GET_SHORT_TERM_DATA = "request_get_short_term_data";
16+
public final static String REQUEST_POST_LONG_TERM_DATA = "request_post_long_term_data";
17+
public final static String REQUEST_GET_LONG_TERM_DATA = "request_get_long_term_data";
1518

1619
public final static String STATUS_ERROR = "error";
1720
public final static String STATUS_OK = "ok";
@@ -24,6 +27,12 @@ public class PacketConst {
2427
public final static String ERROR_ILLEGAL_ARGUMENT = "server_illegal_argument";
2528
public final static String ERROR_FORBIDDEN = "server_forbidden";
2629

30+
public final static String ERROR_DATA_NO_MATCHING_DATA = "No matching Data Available";
31+
public final static String ERROR_DATA_DEVICE_INFO_NOT_MATCH = "Device Information is invalid comparing from stored data";
32+
public final static String ERROR_DATA_DEVICE_INFO_NOT_AVAILABLE = "Device Information is not available";
33+
public final static String ERROR_DATA_DB_IO_FAILED_READ = "IO Failed while reading from stored db";
34+
public final static String ERROR_DATA_DB_IO_FAILED_WRITE = "IO Failed while writing to persistent db";
35+
2736
public final static String KEY_DEVICE_ID = "device_id";
2837
public final static String KEY_DEVICE_NAME = "device_name";
2938
public final static String KEY_SEND_DEVICE_ID = "send_device_id";

app/src/main/java/com/noti/main/service/refiler/ReFileActivity.java

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,19 @@
2121

2222
import com.google.android.material.appbar.MaterialToolbar;
2323
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
24-
import com.google.firebase.storage.FirebaseStorage;
25-
import com.google.firebase.storage.StorageReference;
26-
import com.google.firebase.storage.StreamDownloadTask;
2724

2825
import com.noti.main.Application;
2926
import com.noti.main.R;
27+
import com.noti.main.service.backend.PacketConst;
28+
import com.noti.main.service.backend.PacketRequester;
29+
import com.noti.main.service.backend.ResultPacket;
3030
import com.noti.main.utils.ui.ToastHelper;
3131

3232
import org.json.JSONException;
3333
import org.json.JSONObject;
3434

35-
import java.io.BufferedReader;
3635
import java.io.IOException;
37-
import java.io.InputStream;
38-
import java.io.InputStreamReader;
39-
import java.io.Reader;
4036
import java.net.URLConnection;
41-
import java.nio.charset.StandardCharsets;
4237
import java.text.CharacterIterator;
4338
import java.text.SimpleDateFormat;
4439
import java.text.StringCharacterIterator;
@@ -82,7 +77,7 @@ public void handleOnBackPressed() {
8277
protected void onCreate(@Nullable Bundle savedInstanceState) {
8378
super.onCreate(savedInstanceState);
8479
setContentView(R.layout.activity_refiler);
85-
getWindow().setStatusBarColor(getResources().getColor(R.color.ui_bg_toolbar));
80+
getWindow().setStatusBarColor(getResources().getColor(R.color.ui_bg_toolbar, null));
8681
prefs = getSharedPreferences(Application.PREFS_NAME, Context.MODE_PRIVATE);
8782

8883
Intent intent = getIntent();
@@ -131,46 +126,46 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
131126

132127
void loadQueryFromDB() {
133128
showProgress("Retrieving file list from database...");
134-
FirebaseStorage storage = FirebaseStorage.getInstance();
135-
StorageReference storageRef = storage.getReferenceFromUrl("gs://notisender-41c1b.appspot.com");
136-
StorageReference fileRef = storageRef.child(prefs.getString("UID", "") + "/deviceFileQuery/" + device_id);
137-
StreamDownloadTask downloadTask = fileRef.getStream();
138-
139-
downloadTask.addOnSuccessListener(taskSnapshot -> {
140-
showProgress("Parsing file list...");
141-
new Thread(() -> {
142-
RemoteFile remoteFile = null;
143-
InputStream stream = taskSnapshot.getStream();
144-
StringBuilder textBuilder = new StringBuilder();
145-
try (Reader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
146-
int c;
147-
while ((c = reader.read()) != -1) {
148-
textBuilder.append((char) c);
149-
}
150-
} catch (IOException e) {
151-
runOnUiThread(() -> showError("An error occurred: Cannot read from stream"));
152-
e.printStackTrace();
153-
}
154-
155-
try {
156-
remoteFile = new RemoteFile(new JSONObject(textBuilder.toString()));
157-
} catch (JSONException e) {
158-
runOnUiThread(() -> showError("An error occurred: Cannot parse raw JSON"));
159-
e.printStackTrace();
160-
}
129+
try {
130+
JSONObject serverBody = new JSONObject();
131+
serverBody.put(PacketConst.KEY_ACTION_TYPE, PacketConst.REQUEST_GET_LONG_TERM_DATA);
132+
serverBody.put(PacketConst.KEY_SEND_DEVICE_NAME, device_name);
133+
serverBody.put(PacketConst.KEY_SEND_DEVICE_ID, device_id);
134+
serverBody.put(PacketConst.KEY_DATA_KEY, device_id);
135+
136+
PacketRequester.addToRequestQueue(ReFileActivity.this, PacketConst.SERVICE_TYPE_FILE_LIST, serverBody,
137+
normalResponse -> responseQueryFromDB(normalResponse.toString()),
138+
errorResponse -> responseQueryFromDB(new String(errorResponse.networkResponse.data)));
139+
} catch (Exception e) {
140+
showErrorException(e);
141+
}
142+
}
161143

162-
if (remoteFile != null) {
163-
allFileList = remoteFile;
164-
if(lastRemoteFile != null) {
165-
findLastMatchedFolder();
166-
}
144+
void responseQueryFromDB(String rawMessage) {
145+
try {
146+
RemoteFile remoteFile;
147+
ResultPacket resultPacket = ResultPacket.parseFrom(rawMessage);
167148

168-
runOnUiThread(this::loadFileListLayout);
149+
if (resultPacket.isResultOk()) {
150+
remoteFile = new RemoteFile(new JSONObject(resultPacket.getExtraData()));
151+
allFileList = remoteFile;
152+
if(lastRemoteFile != null) {
153+
findLastMatchedFolder();
169154
}
170-
}).start();
171-
});
155+
runOnUiThread(this::loadFileListLayout);
156+
} else if(resultPacket.getErrorCause().equals(PacketConst.ERROR_DATA_NO_MATCHING_DATA)) {
157+
loadFreshQuery();
158+
} else {
159+
runOnUiThread(() -> showError(resultPacket.getErrorCause()));
160+
}
161+
} catch (IOException | JSONException e) {
162+
showErrorException(e);
163+
}
164+
}
172165

173-
downloadTask.addOnFailureListener(e -> loadFreshQuery());
166+
void showErrorException(Exception e) {
167+
e.printStackTrace();
168+
runOnUiThread(() -> showError(e.getMessage()));
174169
}
175170

176171
void findLastMatchedFolder() {

app/src/main/java/com/noti/main/service/refiler/RemoteFileProcess.java

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
import androidx.annotation.Nullable;
1212

13-
import com.google.firebase.storage.FirebaseStorage;
14-
import com.google.firebase.storage.StorageMetadata;
15-
import com.google.firebase.storage.StorageReference;
1613
import com.noti.main.Application;
1714
import com.noti.main.BuildConfig;
1815
import com.noti.main.receiver.plugin.PluginActions;
1916
import com.noti.main.receiver.plugin.PluginHostInject;
2017
import com.noti.main.receiver.plugin.PluginPrefs;
2118
import com.noti.main.service.NotiListenerService;
19+
import com.noti.main.service.backend.PacketConst;
20+
import com.noti.main.service.backend.PacketRequester;
21+
import com.noti.main.service.backend.ResultPacket;
2222
import com.noti.main.ui.prefs.custom.PluginFragment;
2323
import com.noti.main.utils.PowerUtils;
2424

@@ -28,7 +28,6 @@
2828
import java.io.IOException;
2929
import java.io.InputStream;
3030
import java.net.URLConnection;
31-
import java.nio.charset.StandardCharsets;
3231
import java.util.ArrayList;
3332
import java.util.Locale;
3433
import java.util.Map;
@@ -182,28 +181,40 @@ static void processFileList(Context context, InputStream inputStream) throws IOE
182181
}
183182
String jsonData = buffer.toString();
184183

185-
SharedPreferences prefs = context.getSharedPreferences(Application.PREFS_NAME, Context.MODE_PRIVATE);
186-
FirebaseStorage storage = FirebaseStorage.getInstance();
187-
188-
StorageReference storageRef = storage.getReferenceFromUrl("gs://notisender-41c1b.appspot.com");
189-
StorageReference fileRef = storageRef.child(prefs.getString("UID", "") + "/deviceFileQuery/" + NotiListenerService.getUniqueID());
190-
StorageMetadata metadata = new StorageMetadata.Builder().setContentType("application/json").build();
191-
192-
if(!jsonData.isEmpty()) {
193-
fileRef.putBytes(new JSONObject(jsonData).toString().getBytes(StandardCharsets.UTF_8), metadata)
194-
.addOnSuccessListener(task -> {
184+
try {
185+
JSONObject serverBody = new JSONObject();
186+
serverBody.put(PacketConst.KEY_ACTION_TYPE, PacketConst.REQUEST_POST_LONG_TERM_DATA);
187+
serverBody.put(PacketConst.KEY_DATA_KEY, NotiListenerService.getUniqueID());
188+
serverBody.put(PacketConst.KEY_EXTRA_DATA, jsonData);
189+
190+
PacketRequester.addToRequestQueue(context, PacketConst.SERVICE_TYPE_FILE_LIST, serverBody, response -> {
191+
try {
192+
ResultPacket resultPacket = ResultPacket.parseFrom(response.toString());
193+
if (resultPacket.isResultOk()) {
195194
for(String devices : waitingDeviceList) {
196195
String[] devicesInfo = devices.split("\\|");
197196
pushResponseQuery(context, devicesInfo[0], devicesInfo[1], true, null);
198197
}
199-
isBusy = false;
200-
}).addOnFailureListener(e -> {
201-
for(String devices : waitingDeviceList) {
202-
String[] devicesInfo = devices.split("\\|");
203-
pushResponseQuery(context, devicesInfo[0], devicesInfo[1], false, e.getMessage());
204-
}
205-
isBusy = false;
206-
});
198+
} else {
199+
sendErrorPacket(context, resultPacket.getErrorCause());
200+
}
201+
} catch (IOException e) {
202+
sendErrorPacket(context, e.getMessage());
203+
e.printStackTrace();
204+
} finally {
205+
isBusy = false;
206+
}
207+
}, e -> sendErrorPacket(context, e.getMessage()));
208+
} catch (Exception e) {
209+
sendErrorPacket(context, e.getMessage());
210+
e.printStackTrace();
211+
}
212+
}
213+
214+
protected static void sendErrorPacket(Context context, String message) {
215+
for(String devices : waitingDeviceList) {
216+
String[] devicesInfo = devices.split("\\|");
217+
pushResponseQuery(context, devicesInfo[0], devicesInfo[1], false, message);
207218
}
208219
}
209220

0 commit comments

Comments
 (0)