tasker: add action to upload modified articles and switch online

This commit is contained in:
Andrew Dolgov 2013-10-17 18:59:08 +04:00
parent b3dcf3f6d8
commit 458b46df25
5 changed files with 122 additions and 28 deletions

View File

@ -4,17 +4,6 @@
android:layout_height="fill_parent"
android:padding="5dp" >
<CheckBox
android:id="@+id/download_articles"
android:checked="true"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/download_articles_and_go_offline" />
<Button
android:id="@+id/close_button"
android:layout_width="wrap_content"
@ -23,4 +12,25 @@
android:layout_centerHorizontal="true"
android:text="@string/tasker_save_and_close" />
<RadioGroup
android:id="@+id/taskerActions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<RadioButton
android:id="@+id/actionDownload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/download_articles_and_go_offline" />
<RadioButton
android:id="@+id/actionUpload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/synchronize_read_articles_and_go_online" />
</RadioGroup>
</RelativeLayout>

View File

@ -208,4 +208,5 @@
<string name="shortcut_has_been_placed_on_the_home_screen">Shortcut has been placed on the home screen</string>
<string name="download_articles_and_go_offline">Download articles and go offline</string>
<string name="tasker_save_and_close">Save and close</string>
<string name="synchronize_read_articles_and_go_online">Synchronize read articles and go online</string>
</resources>

View File

@ -11,7 +11,9 @@ import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
@ -29,6 +31,7 @@ public class OfflineUploadService extends IntentService {
private String m_sessionId;
private NotificationManager m_nmgr;
private boolean m_uploadInProgress = false;
private boolean m_batchMode = false;
public OfflineUploadService() {
super("OfflineUploadService");
@ -200,10 +203,19 @@ public class OfflineUploadService extends IntentService {
private void uploadSuccess() {
getWritableDb().execSQL("UPDATE articles SET modified = 0");
Intent intent = new Intent();
intent.setAction(INTENT_ACTION_SUCCESS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
sendBroadcast(intent);
if (m_batchMode) {
SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = localPrefs.edit();
editor.putBoolean("offline_mode_active", false);
editor.commit();
} else {
Intent intent = new Intent();
intent.setAction(INTENT_ACTION_SUCCESS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
sendBroadcast(intent);
}
m_readableDb.close();
m_writableDb.close();
@ -257,6 +269,7 @@ public class OfflineUploadService extends IntentService {
}
m_sessionId = intent.getStringExtra("sessionId");
m_batchMode = intent.getBooleanExtra("batchMode", false);
if (!m_uploadInProgress) {
m_uploadInProgress = true;

View File

@ -4,12 +4,14 @@ import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.CommonActivity;
import org.fox.ttrss.OnlineActivity;
import org.fox.ttrss.offline.OfflineDownloadService;
import org.fox.ttrss.offline.OfflineUploadService;
import org.fox.ttrss.util.SimpleLoginManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
@ -24,21 +26,41 @@ public class TaskerReceiver extends BroadcastReceiver {
final Context fContext = context;
if (com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
Log.d(TAG, "about to download stuff!");
final Bundle settings = intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
final int actionId = settings != null ? settings.getInt("actionId", -1) : -1;
Log.d(TAG, "received action id=" + actionId);
SimpleLoginManager loginMgr = new SimpleLoginManager() {
@Override
protected void onLoginSuccess(int requestId, String sessionId, int apiLevel) {
Log.d(TAG, "Got SID=" + sessionId);
Intent intent = new Intent(
fContext,
OfflineDownloadService.class);
intent.putExtra("sessionId", sessionId);
intent.putExtra("batchMode", true);
fContext.startService(intent);
switch (actionId) {
case TaskerSettingsActivity.ACTION_DOWNLOAD:
if (true) {
Intent intent = new Intent(fContext,
OfflineDownloadService.class);
intent.putExtra("sessionId", sessionId);
intent.putExtra("batchMode", true);
fContext.startService(intent);
}
break;
case TaskerSettingsActivity.ACTION_UPLOAD:
if (true) {
Intent intent = new Intent(fContext,
OfflineUploadService.class);
intent.putExtra("sessionId", sessionId);
intent.putExtra("batchMode", true);
fContext.startService(intent);
}
break;
default:
Log.d(TAG, "unknown action id=" + actionId);
}
}
@Override

View File

@ -1,15 +1,23 @@
package org.fox.ttrss.tasker;
import org.fox.ttrss.R;
import org.fox.ttrss.offline.OfflineDownloadService;
import org.fox.ttrss.offline.OfflineUploadService;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class TaskerSettingsActivity extends Activity {
protected static final int ACTION_DOWNLOAD = 0;
protected static final int ACTION_UPLOAD = 1;
private final String TAG = this.getClass().getSimpleName();
protected Bundle m_settings = new Bundle();
@ -18,14 +26,42 @@ public class TaskerSettingsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Bundle settings = getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
Bundle settings = getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
int actionId = settings != null ? settings.getInt("actionId", -1) : -1;
setContentView(R.layout.tasker_settings);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.taskerActions);
switch (actionId) {
case TaskerSettingsActivity.ACTION_DOWNLOAD:
radioGroup.check(R.id.actionDownload);
break;
case TaskerSettingsActivity.ACTION_UPLOAD:
radioGroup.check(R.id.actionUpload);
break;
default:
Log.d(TAG, "unknown action id=" + actionId);
}
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.actionDownload:
m_settings.putInt("actionId", ACTION_DOWNLOAD);
break;
case R.id.actionUpload:
m_settings.putInt("actionId", ACTION_UPLOAD);
break;
}
}
});
Button button = (Button)findViewById(R.id.close_button);
button.setOnClickListener(new OnClickListener() {
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
@ -38,7 +74,19 @@ public class TaskerSettingsActivity extends Activity {
final Intent intent = new Intent();
intent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE, m_settings);
intent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_STRING_BLURB, getString(R.string.download_articles_and_go_offline));
String blurb = "?";
switch (m_settings.getInt("actionId")) {
case TaskerSettingsActivity.ACTION_DOWNLOAD:
blurb = getString(R.string.download_articles_and_go_offline);
break;
case TaskerSettingsActivity.ACTION_UPLOAD:
blurb = getString(R.string.synchronize_read_articles_and_go_online);
break;
}
intent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_STRING_BLURB, blurb);
setResult(RESULT_OK, intent);