Skip to content
This repository was archived by the owner on Mar 30, 2025. It is now read-only.

Commit bb2d955

Browse files
committed
Forward to "My data" activity if login is required, #345
1 parent c194883 commit bb2d955

File tree

5 files changed

+49
-36
lines changed

5 files changed

+49
-36
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ android {
3636
applicationId "de.bahnhoefe.deutschlands.bahnhofsfotos"
3737
minSdkVersion 26
3838
targetSdkVersion 33
39-
versionCode 68
40-
versionName "13.5.0"
39+
versionCode 69
40+
versionName "13.6.0"
4141
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4242
testInstrumentationRunnerArgument("runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder")
4343
multiDexEnabled true

app/src/main/java/de/bahnhoefe/deutschlands/bahnhofsfotos/ProblemReportActivity.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ private boolean isNotLoggedIn() {
135135
public void reportProblem(View view) {
136136
if (isNotLoggedIn()) {
137137
Toast.makeText(this, R.string.please_login, Toast.LENGTH_LONG).show();
138+
startActivity(new Intent(ProblemReportActivity.this, MyDataActivity.class));
139+
finish();
138140
return;
139141
}
140142

@@ -192,11 +194,12 @@ public void onResponse(@NonNull Call<InboxResponse> call, @NonNull Response<Inbo
192194
if (response.isSuccessful()) {
193195
inboxResponse = response.body();
194196
} else if (response.code() == 401) {
195-
SimpleDialogs.confirm(ProblemReportActivity.this, R.string.authorization_failed);
197+
Toast.makeText(ProblemReportActivity.this, R.string.authorization_failed, Toast.LENGTH_LONG).show();
198+
startActivity(new Intent(ProblemReportActivity.this, MyDataActivity.class));
199+
finish();
196200
return;
197201
} else {
198-
Gson gson = new Gson();
199-
inboxResponse = gson.fromJson(response.errorBody().charStream(), InboxResponse.class);
202+
inboxResponse = new Gson().fromJson(response.errorBody().charStream(), InboxResponse.class);
200203
}
201204

202205
upload.setRemoteId(inboxResponse.getId());

app/src/main/java/de/bahnhoefe/deutschlands/bahnhofsfotos/UploadActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ public void takePicture(View view) {
254254

255255
if (isNotLoggedIn()) {
256256
Toast.makeText(this, R.string.please_login, Toast.LENGTH_LONG).show();
257+
startActivity(new Intent(UploadActivity.this, MyDataActivity.class));
258+
finish();
259+
return;
257260
}
258261

259262
assertCurrentPhotoUploadExists();
@@ -296,6 +299,8 @@ public void takePicture(View view) {
296299
public void selectPicture(View view) {
297300
if (isNotLoggedIn()) {
298301
Toast.makeText(this, R.string.please_login, Toast.LENGTH_LONG).show();
302+
startActivity(new Intent(UploadActivity.this, MyDataActivity.class));
303+
finish();
299304
return;
300305
}
301306

@@ -394,6 +399,8 @@ public void navigateUp() {
394399
public void upload(View view) {
395400
if (isNotLoggedIn()) {
396401
Toast.makeText(this, R.string.please_login, Toast.LENGTH_LONG).show();
402+
startActivity(new Intent(UploadActivity.this, MyDataActivity.class));
403+
finish();
397404
return;
398405
} else if (TextUtils.isEmpty(binding.upload.etStationTitle.getText())) {
399406
Toast.makeText(this, R.string.station_title_needed, Toast.LENGTH_LONG).show();
@@ -456,7 +463,8 @@ public void onResponse(@NonNull Call<InboxResponse> call, @NonNull Response<Inbo
456463
if (response.isSuccessful()) {
457464
inboxResponse = response.body();
458465
} else if (response.code() == 401) {
459-
SimpleDialogs.confirm(UploadActivity.this, R.string.authorization_failed);
466+
Toast.makeText(UploadActivity.this, R.string.authorization_failed, Toast.LENGTH_LONG).show();
467+
startActivity(new Intent(UploadActivity.this, MyDataActivity.class));
460468
return;
461469
} else {
462470
assert response.errorBody() != null;

app/src/main/java/de/bahnhoefe/deutschlands/bahnhofsfotos/rsapi/RSAPIClient.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import com.google.gson.GsonBuilder;
1111

12+
import org.apache.commons.lang3.StringUtils;
13+
1214
import java.util.List;
1315
import java.util.concurrent.atomic.AtomicBoolean;
1416
import java.util.concurrent.atomic.AtomicInteger;
@@ -96,7 +98,7 @@ public void setCredentials(String username, String password) {
9698
}
9799

98100
public boolean hasCredentials() {
99-
return username != null && password != null;
101+
return StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password);
100102
}
101103

102104
public void clearCredentials() {
@@ -128,39 +130,37 @@ public void onFailure(@NonNull Call<List<Country>> call, @NonNull Throwable t) {
128130
var countryCodes = baseApplication.getCountryCodes();
129131
var overallSuccess = new AtomicBoolean(true);
130132
var runningRequestCount = new AtomicInteger(countryCodes.size());
131-
countryCodes.forEach(countryCode -> {
132-
api.getPhotoStationsByCountry(countryCode).enqueue(new Callback<PhotoStations>() {
133-
@Override
134-
public void onResponse(@NonNull Call<PhotoStations> call, @NonNull Response<PhotoStations> response) {
135-
var stationList = response.body();
136-
if (response.isSuccessful() && stationList != null) {
137-
baseApplication.getDbAdapter().insertStations(stationList, countryCode);
138-
baseApplication.setLastUpdate(System.currentTimeMillis());
139-
}
140-
if (!response.isSuccessful()) {
141-
overallSuccess.set(false);
142-
}
143-
onResult(response.isSuccessful());
133+
countryCodes.forEach(countryCode -> api.getPhotoStationsByCountry(countryCode).enqueue(new Callback<PhotoStations>() {
134+
@Override
135+
public void onResponse(@NonNull Call<PhotoStations> call, @NonNull Response<PhotoStations> response) {
136+
var stationList = response.body();
137+
if (response.isSuccessful() && stationList != null) {
138+
baseApplication.getDbAdapter().insertStations(stationList, countryCode);
139+
baseApplication.setLastUpdate(System.currentTimeMillis());
144140
}
145-
146-
@Override
147-
public void onFailure(@NonNull Call<PhotoStations> call, @NonNull Throwable t) {
148-
Log.e(TAG, "Error refreshing stations", t);
149-
Toast.makeText(context, context.getString(R.string.station_update_failed) + t.getMessage(), Toast.LENGTH_LONG).show();
150-
onResult(false);
141+
if (!response.isSuccessful()) {
142+
overallSuccess.set(false);
151143
}
144+
onResult(response.isSuccessful());
145+
}
152146

153-
void onResult(boolean success) {
154-
var stillRunningRequests = runningRequestCount.decrementAndGet();
155-
if (!success) {
156-
overallSuccess.set(false);
157-
}
158-
if (stillRunningRequests == 0) {
159-
listener.onResult(overallSuccess.get());
160-
}
147+
@Override
148+
public void onFailure(@NonNull Call<PhotoStations> call, @NonNull Throwable t) {
149+
Log.e(TAG, "Error refreshing stations", t);
150+
Toast.makeText(context, context.getString(R.string.station_update_failed) + t.getMessage(), Toast.LENGTH_LONG).show();
151+
onResult(false);
152+
}
153+
154+
void onResult(boolean success) {
155+
var stillRunningRequests = runningRequestCount.decrementAndGet();
156+
if (!success) {
157+
overallSuccess.set(false);
161158
}
162-
});
163-
});
159+
if (stillRunningRequests == 0) {
160+
listener.onResult(overallSuccess.get());
161+
}
162+
}
163+
}));
164164

165165
}
166166

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- New: forward to "My data" activity if login is required
2+
- Update dependencies

0 commit comments

Comments
 (0)