Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions res/layout/activity_journal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,28 @@
android:layout_height="1px"
android:background="?android:attr/listDivider" />

<ListView
android:id="@android:id/list"
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/journal_title" />
android:layout_height="match_parent">

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text="@string/journal_title" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/retry_all_button_text"
android:id="@+id/button"
android:drawableLeft="@android:drawable/ic_menu_rotate"
android:drawableStart="@android:drawable/presence_online"
android:drawablePadding="0dip"
android:layout_gravity="right|bottom"
android:onClick="retryAll" />

</FrameLayout>

</LinearLayout>
6 changes: 5 additions & 1 deletion res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Um deinen eigenen Server zu installieren und konfigurieren, schaue bitte hier:</
<string name="app_version">PhotoBackup Version %1$s</string>
<string name="cancel">Abbrechen</string>
<string name="info_conf">Informationen</string>
<string name="journal_backedup">Gespeichert</string>
<string name="journal_backedup">Fertig</string>
<string name="journal_error">Fehler</string>
<string name="journal_noaccess">Starte erst den Dienst um das Protokoll zu sehen</string>
<string name="journal_title">Upload Protokoll</string>
Expand Down Expand Up @@ -42,4 +42,8 @@ Um deinen eigenen Server zu installieren und konfigurieren, schaue bitte hier:</
<string name="toast_serverpassempty">Passwort darf nicht leer sein!</string>
<string name="toast_test_configuration">Server testen</string>
<string name="toast_urisyntaxexception">Die Serveradresse ist ungültig.</string>
<string name="select_folder">Ordner zur Sicherung auswählen</string>
<string name="retry_all_text">Alle Dateien erneut hochladen, die noch nicht als Gespeichert markiert sind. (Maximal %d pro Vorgang, keine älteren als 6 Monate)</string>
<string name="retry_all_title">Ungespeicherte erneut hochladen</string>
<string name="retry_all_button_text">Erneut versuchen</string>
</resources>
2 changes: 2 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
<item>@string/not_only_recent_upload</item>
</string-array>

<string-array name="empty_array"/>

</resources>
7 changes: 6 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<string name="toast_configuration_ko">Server test failed, please verify your configuration.</string>
<string name="toast_permission_not_granted">PhotoBackup cannot work properly without the permission to read your pictures.</string>

<string name="info_conf">Informations</string>
<string name="info_conf">Information</string>
<string name="journal_title">Upload journal</string>
<string name="journal_noaccess">Launch the service to access the journal.</string>
<string name="journal_backedup">Saved</string>
Expand All @@ -60,5 +60,10 @@
<string name="thumbnail_description">Thumbnail of the photo</string>
<string name="manual_backup_title">Manual backup</string>
<string name="manual_backup_message">Save this picture now!</string>
<string name="select_folder">Select photo folder to backup</string>

<string name="retry_all_button_text">Retry unsaved</string>
<string name="retry_all_title">Retry all unsaved</string>
<string name="retry_all_text">Retry all media files that are currently not marked as "Saved" (Max. %d at once, not older than 6 months).</string>

</resources>
10 changes: 10 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
android:entryValues="@array/pref_upload_values"
android:defaultValue="@string/only_recent_upload" />

<MultiSelectListPreference
android:key="PREF_BUCKETS"
android:title="@string/select_folder"
android:summary=""
android:entries="@array/empty_array"
android:defaultValue="@array/empty_array"
android:enabled="false"
android:entryValues="@array/empty_array"
/>

<PreferenceCategory
android:title="@string/info_conf"
android:key="info_conf">
Expand Down
36 changes: 35 additions & 1 deletion src/fr/s13d/photobackup/PBJournalActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import android.widget.ListView;
import android.widget.ToggleButton;

import java.util.List;

import fr.s13d.photobackup.interfaces.PBMediaSenderInterface;


Expand Down Expand Up @@ -128,12 +130,44 @@ public void onClick(DialogInterface dialog, int id) {
// buttons call //
//////////////////
public void clickOnSaved(View v) {
Log.i("PBJournalActivity", "clickOnSaved");
Log.i(LOG_TAG, "clickOnSaved");
ToggleButton btn = (ToggleButton)v;
preferencesEditor.putBoolean(PBMedia.PBMediaState.SYNCED.name(), btn.isChecked()).apply();
adapter.getFilter().filter(null);
}

public void retryAll(View v){
Log.i(LOG_TAG, "retryAll");

final int maxPics = 100;

final Activity self = this;
final AlertDialog.Builder builder = new AlertDialog.Builder(self);
builder.setTitle(self.getResources().getString(R.string.retry_all_title))
.setMessage(self.getResources().getString(R.string.retry_all_text, maxPics));

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {

int count = maxPics;
List<PBMedia> allMedia = PBActivity.getMediaStore().getMedias();
for (PBMedia media: allMedia){
// only save images younger than 6 months + not green yet
if (media.isUnsaved() && media.getAge() < 60 * 60 * 24 * 30 * 6) {
getMediaSender().send(media, true);
if ((count -= 1) == 0) {
break;
}
}
}
}
});
builder.setNegativeButton(self.getString(R.string.cancel), null);
builder.create().show();


//getMediaSender().send(media, true);
}

public void clickOnWaiting(View v) {
Log.i("PBJournalActivity", "clickOnWaiting");
Expand Down
14 changes: 12 additions & 2 deletions src/fr/s13d/photobackup/PBMedia.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,25 @@ public PBMedia(Context context, Cursor mediaCursor) {
public String toString() {
return "PBMedia: " + this.path;
}


/////////////////////////////////////////
// Getters/Setters are the Java fun... //
/////////////////////////////////////////
public int getId() {
return this.id;
}

public boolean isUnsaved() {
return state == PBMedia.PBMediaState.ERROR || state == PBMedia.PBMediaState.WAITING;
}

/**
* Age of media
* @return age in seconds
*/
public long getAge() {
return System.currentTimeMillis() / 1000 - dateAdded;
}

public String getPath() {
return this.path;
}
Expand Down
31 changes: 18 additions & 13 deletions src/fr/s13d/photobackup/PBMediaSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void send(final PBMedia media, boolean manual) {
String uploadRecentOnlyString = prefs.getString(PBPreferenceFragment.PREF_RECENT_UPLOAD_ONLY,
context.getResources().getString(R.string.only_recent_upload_default));
Boolean uploadRecentOnly = uploadRecentOnlyString.equals(context.getResources().getString(R.string.only_recent_upload));
Boolean recentPicture = (System.currentTimeMillis() / 1000 - media.getDateAdded()) < 600;
Boolean recentPicture = media.getAge() < 600;

// test to send or not
if (manual || (!wifiOnly || onWifi) && (!uploadRecentOnly || recentPicture)) {
Expand All @@ -127,13 +127,16 @@ private void sendMedia(final PBMedia media) {
getOkClient().newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.i(LOG_TAG, "Get response with code " + response.code());
if (response.code() == 200) {
sendDidSucceed(media);
} else {
sendDidFail(media, new Throwable(response.message()));
try {
Log.i(LOG_TAG, "Get response with code " + response.code());
if (response.isSuccessful() || response.code() == 409) {
sendDidSucceed(media);
} else {
sendDidFail(media, new Throwable(response.message()));
}
} finally {
response.body().close();
}
response.body().close();
}

@Override
Expand Down Expand Up @@ -163,12 +166,15 @@ public void test() {
getOkClient().newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful() || response.code() == 409) {
testDidSucceed(toast);
} else {
testDidFail(toast, response.message());
try {
if (response.isSuccessful()) {
testDidSucceed(toast);
} else {
testDidFail(toast, response.message());
}
} finally {
response.body().close();
}
response.body().close();
}

@Override
Expand All @@ -195,7 +201,6 @@ private Request makePostRequest(RequestBody requestBody, String pathSuffix) {
return requestBuilder.build();
}


/////////////////////
// Private methods //
/////////////////////
Expand Down
66 changes: 31 additions & 35 deletions src/fr/s13d/photobackup/PBMediaStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class PBMediaStore {
private static SyncMediaStoreTask syncTask;
private static SharedPreferences picturesPreferences;
private static SharedPreferences.Editor picturesPreferencesEditor;
public static final String PhotoBackupPicturesSharedPreferences = "PhotoBackupPicturesSharedPreferences";
private static PBMediaStoreQueries queries;
private List<PBMediaStoreInterface> interfaces = new ArrayList<>();


Expand All @@ -51,7 +53,7 @@ public PBMediaStore(Context theContext) {
picturesPreferences = context.getSharedPreferences(PBApplication.PB_PICTURES_SHARED_PREFS, Context.MODE_PRIVATE);
picturesPreferencesEditor = picturesPreferences.edit();
picturesPreferencesEditor.apply();

queries = new PBMediaStoreQueries(context);
}


Expand All @@ -65,6 +67,14 @@ private static void setPicturesPreferencesEditorToNull(){
picturesPreferencesEditor = null;
}

public PBMedia getLastMediaInStore() {
int id = queries.getLastMediaIdInStore();
return getMedia(id);
}

public PBMediaStoreQueries getQueries() {
return queries;
}

public void addInterface(PBMediaStoreInterface storeInterface) {
interfaces.add(storeInterface);
Expand All @@ -83,27 +93,30 @@ public void close() {


public PBMedia getMedia(int id) {

PBMedia media = null;
if (id != 0) {
final Cursor cursor = context.getContentResolver().query(uri, null, "_id = " + id, null, null);
if (cursor != null && cursor.moveToFirst()) {
media = new PBMedia(context, cursor);
if (id == 0) {
return null;
}
Cursor cursor = queries.getMediaById(id);
if (cursor == null) {
Log.e(LOG_TAG, "Photo not returned. Probably filtered by Bucket or deleted");
return null;
}
Integer idCol = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);
queries.isSelectedBucket(cursor.getString(idCol));

try {
String stateString = picturesPreferences.getString(String.valueOf(media.getId()), PBMedia.PBMediaState.WAITING.name());
media.setState(PBMedia.PBMediaState.valueOf(stateString));
}
catch (Exception e) {
Log.e(LOG_TAG, "Explosion!!");
}
}

if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
media = new PBMedia(context, cursor);
try {
String stateString = picturesPreferences.getString(String.valueOf(media.getId()), PBMedia.PBMediaState.WAITING.name());
media.setState(PBMedia.PBMediaState.valueOf(stateString));
} catch (Exception e) {
Log.e(LOG_TAG, "Explosion!!");
}

if (!cursor.isClosed()) {
cursor.close();
}
return media;
}

Expand All @@ -113,17 +126,6 @@ public List<PBMedia> getMedias() {
}


public PBMedia getLastMediaInStore() {
int id = 0;
final String[] projection = new String[] { "_id" };
final Cursor cursor = context.getContentResolver().query(uri, projection, null, null, "date_added DESC");
if (cursor != null && cursor.moveToFirst()) {
int idColumn = cursor.getColumnIndexOrThrow("_id");
id = cursor.getInt(idColumn);
cursor.close();
}
return getMedia(id);
}


/////////////////////////////////
Expand Down Expand Up @@ -153,13 +155,7 @@ protected Void doInBackground(Void... voids) {
Set<String> inCursor = new HashSet<>();

// Get all pictures on device
final String[] projection = new String[] { "_id", "_data", "date_added" };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, projection, null, null, "date_added DESC");
} catch(SecurityException e) {
Log.w(LOG_TAG, e.toString());
}
Cursor cursor = queries.getAllMedia();

// loop through them to sync
PBMedia media;
Expand Down
Loading