Skip to content

Commit

Permalink
5.02
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Nov 27, 2024
1 parent d93f159 commit 9e30140
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.shajikhan.ladspa.amprack"
minSdk 24
targetSdk 34
versionCode 107
versionName '5.01'
versionCode 108
versionName '5.02'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
Expand Down
20 changes: 1 addition & 19 deletions app/src/main/java/com/shajikhan/ladspa/amprack/FirestoreDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public void onFailure(@NonNull Exception e) {

DocumentReference documentReference = collectionReference.document() ;
batch.set(documentReference, data);
myPresets.myPresetsAdapter.addPreset(data);

// db.collection("presets")
// .add(data)
Expand All @@ -259,25 +260,6 @@ public void onSuccess(Void unused) {
"Synced presets successfully",
Toast.LENGTH_LONG)
.show();

Iterator<String> keys = jsonObject.keys();
while(keys.hasNext()) {
String key = keys.next();
JSONObject jo;
try {
jo = jsonObject.getJSONObject(key);
jo.put("uid", auth.getUid());

if (! jo.has("controls") || jo.isNull("controls")) {
Log.d(TAG, String.format ("[sync]: not loading empty preset %s", jo.toString()));
continue;
}

myPresets.myPresetsAdapter.addPreset(MainActivity.JSONtoMap(jo));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}
});
task.addOnFailureListener(new OnFailureListener() {
Expand Down
25 changes: 18 additions & 7 deletions app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,11 @@ public void onClick(View v) {
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mainActivity.presets.fragmentStateAdapter == null) {
MainActivity.alert("Presets not loaded", "Load presets first by switching to the presets Tab.");
return;
}

String text = editText.getText().toString();
if (text.isEmpty())
return;
Expand Down Expand Up @@ -1325,8 +1330,10 @@ public void onClick(View v) {
String result = syncTask.execute(data).get();
Log.d(TAG, "[sync]: " + result);

if (result.isEmpty()) {
if (result == null || result.isEmpty()) {
Log.w(TAG, "[sync]: no presets received from server");
Toast.makeText(mainActivity, "No presets received from server", Toast.LENGTH_SHORT).show();
dialog.dismiss();
return;
}

Expand All @@ -1341,14 +1348,18 @@ public void onClick(View v) {
// Log.d(TAG, "[preset]: " + jo.toString());
// }

if (mainActivity.presets.fragmentStateAdapter.myPresets.myPresetsAdapter.db == null) {
// Toast.makeText(mainActivity, "Cannot upload: db is null", Toast.LENGTH_SHORT).show();
// return;
mainActivity.presets.fragmentStateAdapter.myPresets.myPresetsAdapter.db = new FirestoreDB(mainActivity);
}

mainActivity.presets.fragmentStateAdapter.myPresets.myPresetsAdapter.db.savePresets(j, false, dialog, mainActivity.presets.fragmentStateAdapter.myPresets);
Log.d(TAG, "[sync]: end presets processing");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (JSONException e) {
throw new RuntimeException(e);
} catch (ExecutionException | InterruptedException | JSONException e) {
// throw new RuntimeException(e);
Log.e(TAG, "[sync]: ", e);
Toast.makeText(mainActivity, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/sync_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:hint="Enter IP Address of PC / Smart Pedal"
android:hint="PC / Pedal IP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
Expand Down

0 comments on commit 9e30140

Please sign in to comment.