summaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/fox/ttrss/offline/OfflineDownloadService.java19
-rw-r--r--src/org/fox/ttrss/tasker/TaskerReceiver.java69
-rw-r--r--src/org/fox/ttrss/tasker/TaskerSettingsActivity.java48
3 files changed, 132 insertions, 4 deletions
diff --git a/src/org/fox/ttrss/offline/OfflineDownloadService.java b/src/org/fox/ttrss/offline/OfflineDownloadService.java
index e507c656..2d65c890 100644
--- a/src/org/fox/ttrss/offline/OfflineDownloadService.java
+++ b/src/org/fox/ttrss/offline/OfflineDownloadService.java
@@ -55,6 +55,7 @@ public class OfflineDownloadService extends Service {
private String m_sessionId;
private NotificationManager m_nmgr;
+ private boolean m_batchMode = false;
private boolean m_downloadInProgress = false;
private boolean m_downloadImages = false;
private int m_syncMax;
@@ -139,10 +140,19 @@ public class OfflineDownloadService extends Service {
if (!isCacheServiceRunning()) {
m_nmgr.cancel(NOTIFY_DOWNLOADING);
- 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", true);
+ editor.commit();
+
+ } else {
+ Intent intent = new Intent();
+ intent.setAction(INTENT_ACTION_SUCCESS);
+ intent.addCategory(Intent.CATEGORY_DEFAULT);
+ sendBroadcast(intent);
+ }
} else {
updateNotification(getString(R.string.notify_downloading_images, 0));
}
@@ -473,6 +483,7 @@ public class OfflineDownloadService extends Service {
}
m_sessionId = intent.getStringExtra("sessionId");
+ m_batchMode = intent.getBooleanExtra("batchMode", false);
if (!m_downloadInProgress) {
if (m_downloadImages) ImageCacheService.cleanupCache(this, false);
diff --git a/src/org/fox/ttrss/tasker/TaskerReceiver.java b/src/org/fox/ttrss/tasker/TaskerReceiver.java
new file mode 100644
index 00000000..b1200b38
--- /dev/null
+++ b/src/org/fox/ttrss/tasker/TaskerReceiver.java
@@ -0,0 +1,69 @@
+package org.fox.ttrss.tasker;
+
+import org.fox.ttrss.CommonActivity;
+import org.fox.ttrss.OnlineActivity;
+import org.fox.ttrss.offline.OfflineDownloadService;
+import org.fox.ttrss.util.SimpleLoginManager;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.widget.Toast;
+
+public class TaskerReceiver extends BroadcastReceiver {
+ private final String TAG = this.getClass().getSimpleName();
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.d(TAG, "Got action: " + intent.getAction());
+
+ final Context fContext = context;
+
+ if (com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
+ Log.d(TAG, "about to download stuff!");
+
+ 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);
+ }
+
+ @Override
+ protected void onLoginFailed(int requestId) {
+ Toast toast = Toast.makeText(fContext, "Could not download articles: login failed", Toast.LENGTH_SHORT);
+ toast.show();
+ }
+
+ @Override
+ protected void onLoggingIn(int requestId) {
+ //
+ }
+ };
+
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+
+ String login = prefs.getString("login", "").trim();
+ String password = prefs.getString("password", "").trim();
+
+ if (login.equals("") || password.equals("")) {
+ Toast toast = Toast.makeText(fContext, "Could not download articles: not configured?", Toast.LENGTH_SHORT);
+ toast.show();
+ } else {
+ loginMgr.logIn(context, 1, login, password);
+ }
+ }
+ }
+
+}
diff --git a/src/org/fox/ttrss/tasker/TaskerSettingsActivity.java b/src/org/fox/ttrss/tasker/TaskerSettingsActivity.java
new file mode 100644
index 00000000..50c500d1
--- /dev/null
+++ b/src/org/fox/ttrss/tasker/TaskerSettingsActivity.java
@@ -0,0 +1,48 @@
+package org.fox.ttrss.tasker;
+
+import org.fox.ttrss.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+public class TaskerSettingsActivity extends Activity {
+ private final String TAG = this.getClass().getSimpleName();
+
+ protected Bundle m_settings = new Bundle();
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ //Bundle settings = getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
+
+ setContentView(R.layout.tasker_settings);
+
+ Button button = (Button)findViewById(R.id.close_button);
+
+ button.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+ }
+
+ @Override
+ public void finish() {
+ 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));
+
+ setResult(RESULT_OK, intent);
+
+ super.finish();
+
+ }
+}