Skip to content

Commit

Permalink
Replace temporary cancel logic, fix some bugs, update to 0.1.7, API 34
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Aug 4, 2024
1 parent e6f402a commit 3b85094
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 52 deletions.
13 changes: 4 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ plugins {

android {
namespace 'dev.danielc.fujiapp'
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "dev.danielc.fujiapp"
minSdk 23
targetSdk 33
versionCode 8
versionName "0.1.6"
// externalNativeBuild {
// ndkBuild {
// arguments "NDK_MODULE_PATH+=${rootProject.projectDir}"
// }
// }
targetSdk 34
versionCode 9
versionName "0.1.5"
}

buildTypes {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
<activity
android:name=".FileGallery"
android:exported="false" />
<activity
android:name=".Autosave"
android:exported="false" />
<activity
android:name=".Help"
android:exported="false" />
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/camlib/Camlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public PtpErr(int code) {
public native static int cPtpCloseSession();
public native static String cGetObjectInfo(int handle);
public static JSONObject getObjectInfo(int handle) throws Exception {
return new JSONObject(cGetObjectInfo(handle));
String x = cGetObjectInfo(handle);
if (x == null) return null;
return new JSONObject(x);
}
};
5 changes: 3 additions & 2 deletions app/src/main/java/dev/danielc/fujiapp/Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ public void run() {
}
});
discoveryThread.start();
Log.d("backend", "Ending discovery thread");
}
public native static int cStartDiscovery(Context ctx);
public static native void cancelDiscoveryThread();
public static void cancelDiscoveryThread() {
discoveryThread.interrupt();
}

// Return directory is guaranteed to exist
public static String getDownloads() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/dev/danielc/fujiapp/DownloadQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

abstract public class DownloadQueue {
// LIFO stack
static ArrayList<Object> requests = new ArrayList<Object>();
ArrayList<Object> requests = new ArrayList<Object>();

abstract void perform(Object request);

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/dev/danielc/fujiapp/Frontend.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.danielc.fujiapp;

import android.media.MediaScannerConnection;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
Expand Down Expand Up @@ -91,7 +92,12 @@ public static void print(String arg) {
}

static void downloadingFile(JSONObject info) {
Gallery.downloadingFile();
Gallery.downloadingFile(info);
}

static void downloadedFile(String path) {
Gallery.downloadedFile(path);
MediaScannerConnection.scanFile(MainActivity.instance, new String[] {path}, null, null);
}

public static void print(int resID) {
Expand Down
36 changes: 30 additions & 6 deletions app/src/main/java/dev/danielc/fujiapp/Gallery.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;

public class Gallery extends AppCompatActivity {
private static Gallery instance;

Expand All @@ -47,21 +51,33 @@ static class ImportPopup {
int length;
Thread thread;
}
static ImportPopup importPopup;
static ImportPopup importPopup = null;

static void stopDownloading() {
importPopup.thread.interrupt();
importPopup.window.dismiss();
importPopup.thread = null;
importPopup = null;
}

static void downloadingFile() {
static void downloadingFile(JSONObject oi) {
if (importPopup == null) return;
importPopup.box.post(new Runnable() {
@Override
public void run() {
try {
((TextView)importPopup.box.findViewById(R.id.import_text)).setText(String.format("Downloading %s", oi.getString("filename"), importPopup.length));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
});
}

static void downloadedFile(String filepath) {
if (importPopup == null) return;
importPopup.count++;
importPopup.box.post(new Runnable() {
@Override
public void run() {
((TextView)importPopup.box.findViewById(R.id.import_text)).setText(String.format("Downloading %d/%d", importPopup.count, importPopup.length));
((ProgressBar)importPopup.box.findViewById(R.id.import_progress)).setProgress(importPopup.count * 100 / importPopup.length);
}
});
}
Expand All @@ -78,6 +94,14 @@ public void onClick(View v) {
@Override
public void run() {
Backend.cFujiImportFiles(objectHandles);
importPopup.box.post(new Runnable() {
@Override
public void run() {
importPopup.window.dismiss();
importPopup.thread = null;
importPopup = null;
}
});
}
});
importPopup.thread.start();
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/dev/danielc/fujiapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public int tryConnect() {
if (rc != 0) return rc;
Backend.cancelDiscoveryThread();
Frontend.print("Connection established");
Backend.cancelDiscoveryThread();
handler.post(new Runnable() {
@Override
public void run() {
Expand Down
27 changes: 23 additions & 4 deletions app/src/main/res/layout/popup_import.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Import All"
android:textSize="34sp" />
android:textSize="24sp" />

<TextView
android:id="@+id/import_text"
Expand All @@ -19,17 +19,36 @@
android:text="Will download any photos that you haven't already downloaded."
android:textSize="15sp" />

<Switch
android:id="@+id/import_switch_jpegs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="JPEGs" />

<Switch
android:id="@+id/import_switch_movs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MOVs" />

<Switch
android:id="@+id/import_switch_raws"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RAWs" />

<ProgressBar
android:id="@+id/progressBar"
android:id="@+id/import_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminateOnly="true" />
android:layout_height="wrap_content" />

<Button
android:id="@+id/import_start_stop_button"
style="@style/GoButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/grey_button"
android:text="cancel" />

</LinearLayout>
12 changes: 1 addition & 11 deletions lib/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,20 +408,10 @@ int fuji_discover_ask_connect(void *arg, struct DiscoverInfo *info) {
return 1;
}

volatile static int do_cancel = 0; // TODO: deprecate

JNI_FUNC(void, cancelDiscoveryThread)(JNIEnv *env, jobject thiz) {
do_cancel = 1;
}

int fuji_discovery_check_cancel(void *arg) {
if (app_check_thread_cancel()) {
return 1;
}
if (do_cancel) {
do_cancel = 0;
return 1;
}
return 0;
}

Expand Down Expand Up @@ -449,7 +439,7 @@ JNI_FUNC(jint, cStartDiscovery)(JNIEnv *env, jobject thiz, jobject ctx) {

set_jni_env_ctx(env, ctx);
if (already_discovering) {
plat_dbg("cStartDiscovery called twice");
plat_dbg("cStartDiscovery called twice, sanity check failed");
abort();
}
already_discovering = 1;
Expand Down
1 change: 1 addition & 0 deletions lib/discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ int fuji_discover_thread(struct DiscoverInfo *info, char *client_name, void *arg
}
}

close(open_pcss);
close(tether_fd);
close(con_fd);
close(reg_fd);
Expand Down
4 changes: 2 additions & 2 deletions lib/fuji.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ int ptp_get_partial_exif(struct PtpRuntime *r, int handle, int *offset, int *len
c.arg = &temp;
c.get_more = my_add;

ptp_verbose_log("Exif reader: %d", exif_start_raw(&c));
plat_dbg("Exif reader: %d", exif_start_raw(&c));

if (c.thumb_of == 0 || c.thumb_size == 0) {
rc = ptp_get_partial_object(r, handle, 0xfffffff0, 0x1);
Expand All @@ -298,7 +298,7 @@ int ptp_get_partial_exif(struct PtpRuntime *r, int handle, int *offset, int *len

*offset = c.thumb_of;
*length = c.thumb_size;
ptp_verbose_log("%X -> %X", c.thumb_of, c.thumb_size);
plat_dbg("%X -> %X", c.thumb_of, c.thumb_size);

// Get camera to think we have ended this file stream
rc = ptp_get_partial_object(r, handle, 0xfffffff0, 0x1);
Expand Down
29 changes: 18 additions & 11 deletions lib/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ static inline jclass get_tester_class(JNIEnv *env) {
return (*env)->FindClass(env, "dev/danielc/fujiapp/Tester");
}

void app_downloading_file(const struct PtpObjectInfo *oi) {
plat_dbg("Downloading file %s", oi->filename);
// Photo importer has started downloading a file, send signal
}

jobject jni_to_json(JNIEnv *env, const char *string) {
static jobject jni_to_json(JNIEnv *env, const char *string) {
jclass json_class = (*env)->FindClass(env, "org/json/JSONObject");
jmethodID constructor = (*env)->GetMethodID(env, json_class, "<init>", "(Ljava/lang/String;)V");

Expand All @@ -149,21 +144,33 @@ int app_check_thread_cancel() {
return (int)(*env)->CallBooleanMethod(env, current_thread, is_interrupted_id);
}

void app_downloaded_file(const struct PtpObjectInfo *oi, const char *path) {
plat_dbg("Downloaded file %s", path);

void app_downloading_file(const struct PtpObjectInfo *oi) {
plat_dbg("Downloading file %s", oi->filename);
// Photo importer has started downloading a file, send signal
char oi_buffer[512];
ptp_object_info_json(oi, oi_buffer, sizeof(oi_buffer));

JNIEnv *env = get_jni_env();
(*env)->PushLocalFrame(env, 5);

jobject json = jni_to_json(env, oi_buffer);

jclass frontend_c = (*env)->FindClass(env, "dev/danielc/fujiapp/Frontend");
jclass frontend_c = get_frontend_class(env);
jmethodID id = (*env)->GetStaticMethodID(env, frontend_c, "downloadingFile", "(Lorg/json/JSONObject;)V");
(*env)->CallStaticVoidMethod(env, frontend_c, id, json);

(*env)->DeleteLocalRef(env, json);
(*env)->PopLocalFrame(env, NULL);
}

void app_downloaded_file(const struct PtpObjectInfo *oi, const char *path) {
JNIEnv *env = get_jni_env();
(*env)->PushLocalFrame(env, 5);
plat_dbg("Downloaded file %s", path);

jclass frontend_c = get_frontend_class(env);
jmethodID id = (*env)->GetStaticMethodID(env, frontend_c, "downloadedFile", "(Ljava/lang/String;)V");
(*env)->CallStaticVoidMethod(env, frontend_c, id, (*env)->NewStringUTF(env, path));
(*env)->PopLocalFrame(env, NULL);
}

void app_print_id(int resid) {
Expand Down

0 comments on commit 3b85094

Please sign in to comment.