Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload answered quests #696

Merged
merged 10 commits into from
Jan 7, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import de.westnordost.streetcomplete.settings.SettingsActivity;
import de.westnordost.streetcomplete.settings.SettingsFragment;
import de.westnordost.streetcomplete.settings.QuestSelectionFragment;
import de.westnordost.streetcomplete.statistics.AnswersCounter;
import de.westnordost.streetcomplete.statistics.UploadedAnswersCounter;
import de.westnordost.streetcomplete.statistics.UnsyncedAnswersCounter;
import de.westnordost.streetcomplete.tangram.MapControlsFragment;
import de.westnordost.streetcomplete.tangram.QuestsMapFragment;
import de.westnordost.streetcomplete.util.SerializedSavedState;
Expand All @@ -40,7 +41,8 @@ public interface ApplicationComponent
void inject(SettingsFragment settingsFragment);
void inject(SettingsActivity settingsActivity);

void inject(AnswersCounter answersCounter);
void inject(UploadedAnswersCounter uploadedAnswersCounter);
void inject(UnsyncedAnswersCounter unsyncedAnswersCounter);

void inject(AddOpeningHoursForm addOpeningHoursForm);
void inject(AddRoadNameForm addRoadNameForm);
Expand Down
57 changes: 35 additions & 22 deletions app/src/main/java/de/westnordost/streetcomplete/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.westnordost.streetcomplete;

import android.animation.ObjectAnimator;
import android.support.v4.app.FragmentManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
Expand All @@ -18,6 +17,7 @@
import android.support.annotation.AnyThread;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -46,37 +46,38 @@
import de.westnordost.osmapi.common.errors.OsmApiReadResponseException;
import de.westnordost.osmapi.common.errors.OsmAuthorizationException;
import de.westnordost.osmapi.common.errors.OsmConnectionException;
import de.westnordost.osmapi.map.data.BoundingBox;
import de.westnordost.osmapi.map.data.Element;
import de.westnordost.osmapi.map.data.LatLon;
import de.westnordost.osmapi.map.data.OsmElement;
import de.westnordost.streetcomplete.about.AboutFragment;
import de.westnordost.streetcomplete.data.Quest;
import de.westnordost.streetcomplete.data.QuestAutoSyncer;
import de.westnordost.streetcomplete.data.upload.QuestChangesUploadProgressListener;
import de.westnordost.streetcomplete.data.upload.QuestChangesUploadService;
import de.westnordost.streetcomplete.data.QuestController;
import de.westnordost.streetcomplete.data.download.QuestDownloadProgressListener;
import de.westnordost.streetcomplete.data.download.QuestDownloadService;
import de.westnordost.streetcomplete.data.QuestGroup;
import de.westnordost.streetcomplete.data.VisibleQuestListener;
import de.westnordost.streetcomplete.data.download.QuestDownloadProgressListener;
import de.westnordost.streetcomplete.data.download.QuestDownloadService;
import de.westnordost.streetcomplete.data.osm.OsmQuest;
import de.westnordost.streetcomplete.data.upload.QuestChangesUploadProgressListener;
import de.westnordost.streetcomplete.data.upload.QuestChangesUploadService;
import de.westnordost.streetcomplete.data.upload.VersionBannedException;
import de.westnordost.streetcomplete.location.LocationRequestFragment;
import de.westnordost.streetcomplete.location.LocationState;
import de.westnordost.streetcomplete.location.LocationUtil;
import de.westnordost.streetcomplete.oauth.OAuthPrefs;
import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment;
import de.westnordost.streetcomplete.quests.FindQuestSourceComponent;
import de.westnordost.streetcomplete.quests.OsmQuestAnswerListener;
import de.westnordost.streetcomplete.quests.QuestAnswerComponent;
import de.westnordost.streetcomplete.quests.FindQuestSourceComponent;
import de.westnordost.streetcomplete.settings.SettingsActivity;
import de.westnordost.streetcomplete.statistics.AnswersCounter;
import de.westnordost.streetcomplete.location.LocationState;
import de.westnordost.streetcomplete.statistics.UnsyncedAnswersCounter;
import de.westnordost.streetcomplete.statistics.UploadedAnswersCounter;
import de.westnordost.streetcomplete.tangram.MapFragment;
import de.westnordost.streetcomplete.tangram.QuestsMapFragment;
import de.westnordost.streetcomplete.tools.CrashReportExceptionHandler;
import de.westnordost.streetcomplete.util.SlippyMapMath;
import de.westnordost.streetcomplete.util.SphericalEarthMath;
import de.westnordost.osmapi.map.data.BoundingBox;
import de.westnordost.osmapi.map.data.Element;
import de.westnordost.osmapi.map.data.LatLon;
import de.westnordost.osmapi.map.data.OsmElement;
import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder;

public class MainActivity extends AppCompatActivity implements
Expand Down Expand Up @@ -105,7 +106,8 @@ public class MainActivity extends AppCompatActivity implements
private QuestGroup clickedQuestGroup = null;

private ProgressBar progressBar;
private AnswersCounter answersCounter;
private UploadedAnswersCounter uploadedAnswersCounter;
private UnsyncedAnswersCounter unsyncedAnswersCounter;

private float mapRotation, mapTilt;

Expand Down Expand Up @@ -175,11 +177,22 @@ public void onServiceDisconnected(ComponentName className)
}

Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);

questController.onCreate();

answersCounter = toolbar.findViewById(R.id.answersCounter);
uploadedAnswersCounter = toolbar.findViewById(R.id.uploadedAnswersCounter);
unsyncedAnswersCounter = toolbar.findViewById(R.id.unsyncedAnswersCounter);

unsyncedAnswersCounter.setOnClickListener(view -> {
if (isConnected()) {
uploadChanges();
}
else {
Toast.makeText(MainActivity.this, R.string.offline, Toast.LENGTH_SHORT).show();
}
});

questSource.onCreate(this);

Expand All @@ -206,7 +219,8 @@ public void onServiceDisconnected(ComponentName className)
{
super.onStart();

answersCounter.update();
uploadedAnswersCounter.update();
unsyncedAnswersCounter.update();

registerReceiver(locationAvailabilityReceiver, LocationUtil.createLocationAvailabilityIntentFilter());

Expand Down Expand Up @@ -299,7 +313,7 @@ private void confirmUndo(final OsmQuest quest)
.setPositiveButton(R.string.undo_confirm_positive, (dialog, which) ->
{
questController.undoOsmQuest(quest);
answersCounter.undidQuest(quest.getChangesSource());
unsyncedAnswersCounter.undidQuest(quest.getChangesSource());
})
.setNegativeButton(R.string.undo_confirm_negative, null)
.show();
Expand Down Expand Up @@ -340,10 +354,6 @@ private int getQuestTitleResId(Quest quest, Map<String,String> tags)
if(isConnected()) downloadDisplayedArea();
else Toast.makeText(this, R.string.offline, Toast.LENGTH_SHORT).show();
return true;
case R.id.action_upload:
if(isConnected()) uploadChanges();
else Toast.makeText(this, R.string.offline, Toast.LENGTH_SHORT).show();
return true;
}

return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -473,7 +483,10 @@ else if(e instanceof OsmAuthorizationException)

@AnyThread @Override public void onFinished()
{
runOnUiThread(() -> answersCounter.update());
runOnUiThread(() -> {
uploadedAnswersCounter.update();
unsyncedAnswersCounter.update();
});
}
};

Expand Down Expand Up @@ -586,7 +599,7 @@ else if(e instanceof OsmAuthorizationException)
questSource.findSource(questId, group, locations, source ->
{
closeQuestDetailsFor(questId, group);
answersCounter.answeredQuest(source);
unsyncedAnswersCounter.answeredQuest(source);
questController.solveQuest(questId, group, answer, source);
});
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.westnordost.streetcomplete.statistics;

import android.content.Context;
import android.os.AsyncTask;
import android.util.AttributeSet;

import javax.inject.Inject;

import de.westnordost.streetcomplete.Injector;
import de.westnordost.streetcomplete.data.QuestStatus;
import de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao;

public class UnsyncedAnswersCounter extends android.support.v7.widget.AppCompatTextView {

@Inject
OsmQuestDao questDB;

private int answeredQuests;

public UnsyncedAnswersCounter(Context context, AttributeSet attrs) {
super(context, attrs);
Injector.instance.getApplicationComponent().inject(this);
}

public void answeredQuest(String source) {
answeredQuests++;
updateText();
}

public void undidQuest(String source) {
answeredQuests--;
updateText();
}

public void update() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
answeredQuests = questDB.getCount(null, QuestStatus.ANSWERED);
return null;
}

@Override
protected void onPostExecute(Void result) {
updateText();
}
}.execute();
}

private void updateText() {
setText(String.valueOf(answeredQuests));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.westnordost.streetcomplete.statistics;

import android.content.Context;
import android.os.AsyncTask;
import android.util.AttributeSet;

import javax.inject.Inject;

import de.westnordost.streetcomplete.Injector;
import de.westnordost.streetcomplete.data.statistics.QuestStatisticsDao;

public class UploadedAnswersCounter extends android.support.v7.widget.AppCompatTextView
{
@Inject QuestStatisticsDao questStatisticsDB;

private int solvedQuests;

public UploadedAnswersCounter(Context context)
{
super(context);
init();
}

public UploadedAnswersCounter(Context context, AttributeSet attrs)
{
super(context, attrs);
init();
}

public UploadedAnswersCounter(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
init();
}

private void init()
{
Injector.instance.getApplicationComponent().inject(this);
}

public void update()
{
new AsyncTask<Void, Void, Void>()
{
@Override protected Void doInBackground(Void... params)
{
solvedQuests = questStatisticsDB.getTotalAmount();
return null;
}

@Override protected void onPostExecute(Void result)
{
updateText();
}
}.execute();
}

private void updateText()
{
setText(String.valueOf(solvedQuests));
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_file_upload_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z"/>
</vector>
Loading