Skip to content

Commit 99e3476

Browse files
Merge pull request #49 from PhotoBackup/15-should-handle-301-redirection
Support for Bucket Picker and redirection
2 parents 869a5c9 + 1db908e commit 99e3476

19 files changed

+571
-360
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
minSdkVersion 16
1111
targetSdkVersion 24
1212
versionCode 24
13-
versionName "0.9.0"
13+
versionName "0.10.0"
1414

1515
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1616
}

app/src/main/java/fr/s13d/photobackup/PBActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.view.MenuItem;
2626
import android.widget.Toast;
2727

28+
import fr.s13d.photobackup.media.PBMediaStore;
2829
import fr.s13d.photobackup.preferences.PBPreferenceFragment;
2930

3031
public class PBActivity extends Activity {

app/src/main/java/fr/s13d/photobackup/PBApplication.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,33 @@
1919
package fr.s13d.photobackup;
2020

2121
import android.app.Application;
22+
import android.preference.PreferenceManager;
23+
24+
import java.util.Map;
25+
import java.util.Set;
2226

2327

2428
public class PBApplication extends Application {
2529

2630
private final static String LOG_TAG = "PBApplication";
31+
private static PBApplication app;
32+
2733

2834
@Override
2935
public void onCreate() {
3036
super.onCreate();
31-
Log.e(LOG_TAG, "Initializing app");
37+
Log.d(LOG_TAG, "Initializing app");
38+
app = this;
39+
40+
if (BuildConfig.DEBUG) {
41+
Log.d(LOG_TAG, "Default SharedPreferences:");
42+
Map<String, ?> allPrefs = PreferenceManager.getDefaultSharedPreferences(this).getAll();
43+
Set<String> set = allPrefs.keySet();
44+
for(String s : set) {
45+
Log.d(LOG_TAG, s + "<" + allPrefs.get(s).getClass().getSimpleName() +"> = "
46+
+ allPrefs.get(s).toString());
47+
}
48+
}
3249
}
3350

3451

@@ -38,4 +55,11 @@ public void onCreate() {
3855
public final static String PB_USER_AGENT = "PhotoBackup Android Client v" + BuildConfig.VERSION_NAME;
3956
public static final String PB_PICTURES_SHARED_PREFS = "PB_PICTURES_SHARED_PREFS";
4057

58+
59+
/////////////
60+
// Getters //
61+
/////////////
62+
public static PBApplication getApp() {
63+
return app;
64+
}
4165
}

app/src/main/java/fr/s13d/photobackup/PBMediaStore.java

Lines changed: 0 additions & 214 deletions
This file was deleted.

app/src/main/java/fr/s13d/photobackup/PBService.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
import fr.s13d.photobackup.interfaces.PBMediaSenderInterface;
2929
import fr.s13d.photobackup.interfaces.PBMediaStoreInterface;
30+
import fr.s13d.photobackup.media.PBMedia;
31+
import fr.s13d.photobackup.media.PBMediaSender;
32+
import fr.s13d.photobackup.media.PBMediaStore;
3033

3134

3235
public class PBService extends Service implements PBMediaStoreInterface, PBMediaSenderInterface {
@@ -89,7 +92,7 @@ public PBService getService() {
8992
// Methods //
9093
/////////////
9194
public void sendNextMedia() {
92-
for (PBMedia media : getMediaStore().getMedias()) {
95+
for (PBMedia media : getMediaStore().getMediaList()) {
9396
if (media.getState() != PBMedia.PBMediaState.SYNCED) {
9497
sendMedia(media, false);
9598
break;
@@ -113,9 +116,8 @@ public void onSyncMediaStoreTaskPostExecute() {
113116
//////////////////////////////////////
114117
// PBMediaSenderInterface callbacks //
115118
//////////////////////////////////////
116-
public void onSendSuccess() {
117-
sendNextMedia();
118-
}
119+
public void onMessage(final String message) { }
120+
public void onSendSuccess() { sendNextMedia(); }
119121
public void onSendFailure() {}
120122
public void onTestSuccess() {}
121123
public void onTestFailure() {}
@@ -143,10 +145,11 @@ public void onChange(boolean selfChange, Uri uri) {
143145
if (uri.toString().equals("content://media/external/images/media")) {
144146

145147
try {
146-
final PBMedia media = getMediaStore().getLastMediaInStore();
147-
media.setState(PBMedia.PBMediaState.WAITING);
148-
getMediaSender().send(media, false);
149-
//mediaStore.sync();
148+
final PBMedia media = getMediaStore().createMediaForLatestInStore();
149+
if (media != null) {
150+
media.setState(PBMedia.PBMediaState.WAITING);
151+
getMediaSender().send(media, false);
152+
}
150153
}
151154
catch (Exception e) {
152155
Log.e(LOG_TAG, "Upload failed :-(");
@@ -162,7 +165,7 @@ public void onChange(boolean selfChange, Uri uri) {
162165
/////////////
163166
public PBMediaStore getMediaStore() {
164167
if (mediaStore == null) {
165-
mediaStore = new PBMediaStore(this);
168+
mediaStore = new PBMediaStore();
166169
mediaStore.addInterface(this);
167170
mediaStore.sync();
168171
}
@@ -172,15 +175,15 @@ public PBMediaStore getMediaStore() {
172175

173176
private PBMediaSender getMediaSender() {
174177
if (mediaSender == null) {
175-
mediaSender = new PBMediaSender(this);
178+
mediaSender = new PBMediaSender();
176179
mediaSender.addInterface(this);
177180
}
178181
return mediaSender;
179182
}
180183

181184

182185
public int getMediaSize() {
183-
return getMediaStore().getMedias().size();
186+
return getMediaStore().getMediaList().size();
184187
}
185188

186189

app/src/main/java/fr/s13d/photobackup/PBWifiBroadcastReceiver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
import java.util.List;
3232

33+
import fr.s13d.photobackup.media.PBMedia;
34+
import fr.s13d.photobackup.media.PBMediaStore;
3335
import fr.s13d.photobackup.preferences.PBPreferenceFragment;
3436

3537
public class PBWifiBroadcastReceiver extends BroadcastReceiver {
@@ -72,10 +74,10 @@ public void onReceive(final Context context, final Intent intent) {
7274
if (mediaStore == null) {
7375
return;
7476
}
75-
List<PBMedia> medias = mediaStore.getMedias();
77+
List<PBMedia> medias = mediaStore.getMediaList();
7678
Log.i(LOG_TAG, "media count = " + medias.size());
7779

78-
for (PBMedia media : mediaStore.getMedias()) {
80+
for (PBMedia media : medias) {
7981
// TODO replace with media.isUnsaved after PR merge and getAge
8082
if (media.getAge() < 3600 * 24 * 7 && media.getState() != PBMedia.PBMediaState.SYNCED) {
8183
Log.i(LOG_TAG, "Notify to send " + media.getPath());

app/src/main/java/fr/s13d/photobackup/interfaces/PBMediaSenderInterface.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121

2222
public interface PBMediaSenderInterface {
23+
24+
void onMessage(final String message);
25+
2326
void onSendSuccess();
2427
void onSendFailure();
2528

0 commit comments

Comments
 (0)