summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-10-17 16:33:30 +0400
committerAndrew Dolgov <[email protected]>2013-10-17 16:33:30 +0400
commit68f8880a615e92839ec718b204f7bcd685367b2f (patch)
treeb226e1d0fc324fd752ed3c7c826024330efe6580
parent0ebcf48603c1094faf648bcaece208639dd93323 (diff)
implement tasker action to download articles and go offline
-rw-r--r--AndroidManifest.xml45
-rw-r--r--project.properties5
-rw-r--r--res/layout/tasker_settings.xml26
-rw-r--r--res/values/strings.xml2
-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
7 files changed, 194 insertions, 20 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b753670d..d0a0265d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -16,7 +16,7 @@
<application
android:name=".GlobalState"
android:allowBackup="true"
- android:backupAgent=".util.PrefsBackupAgent"
+ android:backupAgent="org.fox.ttrss.util.PrefsBackupAgent"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name" >
@@ -43,8 +43,8 @@
</activity>
<activity
android:name=".HeadlinesActivity"
- android:uiOptions="splitActionBarWhenNarrow"
- android:label="@string/app_name" >
+ android:label="@string/app_name"
+ android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
@@ -54,6 +54,13 @@
android:label="@string/app_name" >
</activity>
<activity
+ android:name=".tasker.TaskerSettingsActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
+ </intent-filter>
+ </activity>
+ <activity
android:name=".offline.OfflineActivity"
android:label="@string/app_name" >
</activity>
@@ -64,8 +71,8 @@
</activity>
<activity
android:name=".offline.OfflineHeadlinesActivity"
- android:uiOptions="splitActionBarWhenNarrow"
- android:label="@string/app_name" >
+ android:label="@string/app_name"
+ android:uiOptions="splitActionBarWhenNarrow" >
</activity>
<activity
android:name=".share.ShareActivity"
@@ -191,13 +198,20 @@
android:name=".offline.OfflineUploadService"
android:enabled="true" />
<service
- android:name=".util.ImageCacheService"
+ android:name="org.fox.ttrss.util.ImageCacheService"
android:enabled="true" />
<meta-data
android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIwG6zsGB4qo6ZhjfwIJpm9WI7AqmWaoRXm6ZJnA" />
+ <receiver android:name=".tasker.TaskerReceiver" >
+ <intent-filter>
+ <action android:name="com.twofortyfouram.locale.intent.action.QUERY_CONDITION" />
+ <action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
+ </intent-filter>
+ </receiver>
+
<receiver android:name=".widget.SmallWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
@@ -208,23 +222,26 @@
android:name="android.appwidget.provider"
android:resource="@xml/widget_small" />
</receiver>
-
+
<service
android:name=".widget.WidgetUpdateService"
android:enabled="true" />
-
- <service android:name=".DashClock"
+ <service
+ android:name=".DashClock"
android:icon="@drawable/dashclock"
android:label="@string/app_name"
- android:permission="com.google.android.apps.dashclock.permission.READ_EXTENSION_DATA">
+ android:permission="com.google.android.apps.dashclock.permission.READ_EXTENSION_DATA" >
<intent-filter>
<action android:name="com.google.android.apps.dashclock.Extension" />
</intent-filter>
- <meta-data android:name="protocolVersion" android:value="1" />
- <meta-data android:name="description"
+
+ <meta-data
+ android:name="protocolVersion"
+ android:value="1" />
+ <meta-data
+ android:name="description"
android:value="@string/app_name" />
</service>
-
</application>
-</manifest>
+</manifest> \ No newline at end of file
diff --git a/project.properties b/project.properties
index bb236c79..1b18cf3a 100644
--- a/project.properties
+++ b/project.properties
@@ -12,5 +12,6 @@ target=android-17
android.library.reference.1=..\\Android-ViewPagerIndicator\\library
android.library.reference.2=..\\ActionBarSherlock\\actionbarsherlock
android.library.reference.3=..\\SlidingMenu\\library
-android.library.reference.4=../ActionBar-PullToRefresh/library
-android.library.reference.5=../ActionBar-PullToRefresh/extras/pulltorefresh-actionbarsherlock
+android.library.reference.4=..\\ActionBar-PullToRefresh\\library
+android.library.reference.5=..\\ActionBar-PullToRefresh\\extras\\pulltorefresh-actionbarsherlock
+android.library.reference.6=../tasker-locale-api
diff --git a/res/layout/tasker_settings.xml b/res/layout/tasker_settings.xml
new file mode 100644
index 00000000..b96642aa
--- /dev/null
+++ b/res/layout/tasker_settings.xml
@@ -0,0 +1,26 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/main"
+ android:layout_width="fill_parent"
+ 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"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:text="@string/tasker_save_and_close" />
+
+</RelativeLayout> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f854dabf..586ec70a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -206,4 +206,6 @@
<string name="accel_webview_title">Accelerate web views</string>
<string name="place_shortcut">Place shortcut</string>
<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>
</resources>
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();
+
+ }
+}