implement shareintent handler for tt-rss sharing functionality
bump version
This commit is contained in:
parent
4e4739af55
commit
59d11ac972
@ -1,10 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.fox.ttrss"
|
||||
android:versionCode="95"
|
||||
android:versionName="0.7.3" >
|
||||
android:versionCode="96"
|
||||
android:versionName="0.7.4" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="11" />
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:targetSdkVersion="11" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
@ -17,36 +19,46 @@
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:label="@string/app_name"
|
||||
android:name=".LoginActivity" >
|
||||
android:name=".LoginActivity"
|
||||
android:label="@string/app_name" >
|
||||
</activity>
|
||||
<activity
|
||||
android:label="@string/app_name"
|
||||
android:name=".offline.OfflineActivity" >
|
||||
android:name=".offline.OfflineActivity"
|
||||
android:label="@string/app_name" >
|
||||
</activity>
|
||||
<activity
|
||||
android:label="@string/app_name"
|
||||
android:name=".MainActivity" >
|
||||
<intent-filter >
|
||||
android:name=".ShareActivity"
|
||||
android:excludeFromRecents="true"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:label="@string/preferences"
|
||||
android:name=".PreferencesActivity" >
|
||||
android:name=".PreferencesActivity"
|
||||
android:label="@string/preferences" >
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:enabled="true"
|
||||
android:name=".offline.OfflineDownloadService" />
|
||||
android:name=".offline.OfflineDownloadService"
|
||||
android:enabled="true" />
|
||||
<service
|
||||
android:enabled="true"
|
||||
android:name=".offline.OfflineUploadService" />
|
||||
android:name=".offline.OfflineUploadService"
|
||||
android:enabled="true" />
|
||||
<service
|
||||
android:enabled="true"
|
||||
android:name=".util.ImageCacheService" />
|
||||
android:name=".util.ImageCacheService"
|
||||
android:enabled="true" />
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.android.backup.api_key"
|
||||
|
90
res/layout/share.xml
Normal file
90
res/layout/share.xml
Normal file
@ -0,0 +1,90 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TableLayout
|
||||
android:padding="4dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/tableRow1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.3"
|
||||
android:text="Title:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/title"
|
||||
android:singleLine="true"
|
||||
android:layout_width="0dp"
|
||||
android:hint="Article Title"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.7" >
|
||||
</EditText>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/tableRow2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.3"
|
||||
android:text="URL:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/url"
|
||||
android:singleLine="true"
|
||||
android:hint="Article URL"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.7" />
|
||||
</TableRow>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:hint="Article Content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textMultiLine"
|
||||
android:maxLines="3">
|
||||
<requestFocus />
|
||||
</EditText>
|
||||
|
||||
<Button
|
||||
android:id="@+id/share_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Share" />
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/loading_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loading_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/loading_message" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -128,4 +128,5 @@
|
||||
<string name="notify_article_published">Article published</string>
|
||||
<string name="notify_article_unpublished">Article unpublished</string>
|
||||
<string name="notify_article_note_set">Article note saved</string>
|
||||
<string name="api_too_low">This action requires newer version of Tiny Tiny RSS</string>
|
||||
</resources>
|
@ -1411,8 +1411,8 @@ public class MainActivity extends CommonActivity implements OnlineServices {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
|
||||
intent.setType("text/plain");
|
||||
//intent.putExtra(Intent.EXTRA_SUBJECT, article.title);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, article.title + " " + article.link);
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, article.title);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, article.link);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
261
src/org/fox/ttrss/ShareActivity.java
Normal file
261
src/org/fox/ttrss/ShareActivity.java
Normal file
@ -0,0 +1,261 @@
|
||||
package org.fox.ttrss;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class ShareActivity extends CommonActivity {
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
|
||||
private String m_sessionId;
|
||||
private SharedPreferences m_prefs;
|
||||
private int m_apiLevel = 0;
|
||||
private boolean m_isLoggingIn = false;
|
||||
private String m_themeName = "";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
m_prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
||||
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
||||
setTheme(R.style.DarkTheme);
|
||||
} else {
|
||||
setTheme(R.style.LightTheme);
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||
|
||||
m_themeName = m_prefs.getString("theme", "THEME_DARK");
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
m_sessionId = savedInstanceState.getString("sessionId");
|
||||
m_apiLevel = savedInstanceState.getInt("apiLevel");
|
||||
}
|
||||
|
||||
setContentView(R.layout.share);
|
||||
|
||||
setSmallScreen(findViewById(R.id.headlines_fragment) == null);
|
||||
|
||||
if (m_sessionId != null) {
|
||||
loginSuccess();
|
||||
} else {
|
||||
//login(); -- handled in onResume()
|
||||
}
|
||||
}
|
||||
|
||||
private void loginSuccess() {
|
||||
findViewById(R.id.loading_container).setVisibility(View.GONE);
|
||||
setProgressBarIndeterminateVisibility(false);
|
||||
|
||||
if (m_apiLevel < 4) {
|
||||
setLoadingStatus(R.string.api_too_low, false);
|
||||
} else {
|
||||
Intent intent = getIntent();
|
||||
|
||||
final EditText url = (EditText) findViewById(R.id.url);
|
||||
url.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||
|
||||
final EditText title = (EditText) findViewById(R.id.title);
|
||||
title.setText(intent.getStringExtra(Intent.EXTRA_SUBJECT));
|
||||
|
||||
final EditText content = (EditText) findViewById(R.id.content);
|
||||
|
||||
Button share = (Button) findViewById(R.id.share_button);
|
||||
|
||||
share.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ApiRequest req = new ApiRequest(getApplicationContext()) {
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
setProgressBarIndeterminateVisibility(false);
|
||||
|
||||
if (m_lastError != ApiError.NO_ERROR) {
|
||||
toast(getErrorMessage());
|
||||
} else {
|
||||
toast("Article posted.");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>() {
|
||||
{
|
||||
put("sid", m_sessionId);
|
||||
put("op", "shareToPublished");
|
||||
put("title", title.getText().toString());
|
||||
put("url", url.getText().toString());
|
||||
put("content", content.getText().toString());
|
||||
}
|
||||
};
|
||||
|
||||
setProgressBarIndeterminateVisibility(true);
|
||||
|
||||
req.execute(map);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void logout() {
|
||||
m_sessionId = null;
|
||||
|
||||
findViewById(R.id.loading_container).setVisibility(View.VISIBLE);
|
||||
|
||||
TextView tv = (TextView) findViewById(R.id.loading_message);
|
||||
|
||||
if (tv != null) {
|
||||
tv.setText(R.string.login_ready);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "serial" })
|
||||
public void login() {
|
||||
|
||||
logout();
|
||||
|
||||
if (m_prefs.getString("ttrss_url", "").trim().length() == 0) {
|
||||
|
||||
setLoadingStatus(R.string.login_need_configure, false);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(R.string.dialog_need_configure_prompt)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.dialog_open_preferences, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
// launch preferences
|
||||
|
||||
Intent intent = new Intent(ShareActivity.this,
|
||||
PreferencesActivity.class);
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
|
||||
} else {
|
||||
|
||||
LoginRequest ar = new LoginRequest(getApplicationContext());
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>() {
|
||||
{
|
||||
put("op", "login");
|
||||
put("user", m_prefs.getString("login", "").trim());
|
||||
put("password", m_prefs.getString("password", "").trim());
|
||||
}
|
||||
};
|
||||
|
||||
ar.execute(map);
|
||||
|
||||
setLoadingStatus(R.string.login_in_progress, true);
|
||||
|
||||
m_isLoggingIn = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setLoadingStatus(int status, boolean showProgress) {
|
||||
TextView tv = (TextView) findViewById(R.id.loading_message);
|
||||
|
||||
if (tv != null) {
|
||||
tv.setText(status);
|
||||
}
|
||||
|
||||
setProgressBarIndeterminateVisibility(showProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (m_sessionId == null && !m_isLoggingIn) {
|
||||
login();
|
||||
}
|
||||
}
|
||||
|
||||
private class LoginRequest extends ApiRequest {
|
||||
public LoginRequest(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
m_isLoggingIn = false;
|
||||
|
||||
if (result != null) {
|
||||
try {
|
||||
JsonObject content = result.getAsJsonObject();
|
||||
if (content != null) {
|
||||
m_sessionId = content.get("session_id").getAsString();
|
||||
|
||||
Log.d(TAG, "Authenticated!");
|
||||
|
||||
ApiRequest req = new ApiRequest(m_context) {
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
m_apiLevel = 0;
|
||||
|
||||
if (result != null) {
|
||||
try {
|
||||
m_apiLevel = result.getAsJsonObject()
|
||||
.get("level").getAsInt();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(TAG, "Received API level: " + m_apiLevel);
|
||||
|
||||
loginSuccess();
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
HashMap<String, String> map = new HashMap<String, String>() {
|
||||
{
|
||||
put("sid", m_sessionId);
|
||||
put("op", "getApiLevel");
|
||||
}
|
||||
};
|
||||
|
||||
req.execute(map);
|
||||
|
||||
setLoadingStatus(R.string.loading_message, true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
m_sessionId = null;
|
||||
|
||||
setLoadingStatus(getErrorMessage(), false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -569,8 +569,8 @@ public class OfflineActivity extends CommonActivity implements
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
|
||||
intent.setType("text/plain");
|
||||
//intent.putExtra(Intent.EXTRA_SUBJECT, title);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, title + " " + link);
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, title);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, link);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user