implement tasker action to download articles and go offline
This commit is contained in:
parent
0ebcf48603
commit
68f8880a61
@ -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>
|
||||
@ -53,6 +53,13 @@
|
||||
android:name=".CommonActivity"
|
||||
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" >
|
||||
@ -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>
|
@ -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
|
||||
|
26
res/layout/tasker_settings.xml
Normal file
26
res/layout/tasker_settings.xml
Normal file
@ -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>
|
@ -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>
|
||||
|
@ -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);
|
||||
|
69
src/org/fox/ttrss/tasker/TaskerReceiver.java
Normal file
69
src/org/fox/ttrss/tasker/TaskerReceiver.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
48
src/org/fox/ttrss/tasker/TaskerSettingsActivity.java
Normal file
48
src/org/fox/ttrss/tasker/TaskerSettingsActivity.java
Normal file
@ -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();
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user