Removes the product flavor split.

This commit is contained in:
Vavassor 2017-05-18 18:10:46 -04:00
commit 388ecfcf2e
13 changed files with 27 additions and 501 deletions

View file

@ -15,8 +15,6 @@
package com.keylesspalace.tusky;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -24,7 +22,6 @@ import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
@ -55,7 +52,6 @@ public class BaseActivity extends AppCompatActivity {
public MastodonAPI mastodonAPI;
protected PushNotificationClient pushNotificationClient;
protected Dispatcher mastodonApiDispatcher;
protected PendingIntent serviceAlarmIntent;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -156,10 +152,8 @@ public class BaseActivity extends AppCompatActivity {
}
protected void createTuskyAPI() {
if (BuildConfig.USES_PUSH_NOTIFICATIONS) {
// TODO: Remove this test broker address.
pushNotificationClient = new PushNotificationClient(this, "tcp://104.236.116.199:1883");
}
pushNotificationClient = new PushNotificationClient(this,
getString(R.string.tusky_api_url));
}
protected void redirectIfNotLoggedIn() {
@ -193,28 +187,10 @@ public class BaseActivity extends AppCompatActivity {
}
protected void enablePushNotifications() {
if (BuildConfig.USES_PUSH_NOTIFICATIONS) {
pushNotificationClient.subscribeToTopic();
} else {
// Start up the MessagingService on a repeating interval for "pull" notifications.
long checkInterval = 60 * 1000 * 5;
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, MessagingService.class);
final int SERVICE_REQUEST_CODE = 8574603; // This number is arbitrary.
serviceAlarmIntent = PendingIntent.getService(this, SERVICE_REQUEST_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(), checkInterval, serviceAlarmIntent);
}
pushNotificationClient.subscribeToTopic();
}
protected void disablePushNotifications() {
if (BuildConfig.USES_PUSH_NOTIFICATIONS) {
pushNotificationClient.unsubscribeToTopic();
} else if (serviceAlarmIntent != null) {
// Cancel the repeating call for "pull" notifications.
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(serviceAlarmIntent);
}
pushNotificationClient.unsubscribeToTopic();
}
}

View file

@ -215,8 +215,7 @@ public class MainActivity extends BaseActivity implements SFragment.OnUserRemove
.putString("current", "[]")
.apply();
((NotificationManager) (getSystemService(NOTIFICATION_SERVICE)))
.cancel(MessagingService.NOTIFY_ID);
pushNotificationClient.clearNotifications();
/* After editing a profile, the profile header in the navigation drawer needs to be
* refreshed */

View file

@ -26,6 +26,7 @@ import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import okhttp3.Interceptor;
@ -88,20 +89,24 @@ public class PushNotificationClient {
options.setAutomaticReconnect(true);
options.setCleanSession(false);
try {
/* TLS connection stuffs
InputStream input = context.getResources().openRawResource(R.raw.keystore_tusky_api);
/*
String password = context.getString(R.string.tusky_api_keystore_password);
options.setSocketFactory(mqttAndroidClient.getSSLSocketFactory(input, password));
InputStream keystore = context.getResources().openRawResource(R.raw.keystore_tusky_api);
try {
options.setSocketFactory(mqttAndroidClient.getSSLSocketFactory(keystore, password));
} finally {
IOUtils.closeQuietly(keystore);
}
*/
mqttAndroidClient.connect(options).setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
DisconnectedBufferOptions options = new DisconnectedBufferOptions();
options.setBufferEnabled(true);
options.setBufferSize(100);
options.setPersistBuffer(false);
options.setDeleteOldestMessages(false);
mqttAndroidClient.setBufferOpts(options);
DisconnectedBufferOptions bufferOptions = new DisconnectedBufferOptions();
bufferOptions.setBufferEnabled(true);
bufferOptions.setBufferSize(100);
bufferOptions.setPersistBuffer(false);
bufferOptions.setDeleteOldestMessages(false);
mqttAndroidClient.setBufferOpts(bufferOptions);
onConnectionSuccess();
connected = true;
flushQueuedActions();
@ -253,4 +258,8 @@ public class PushNotificationClient {
mastodonApi = retrofit.create(MastodonAPI.class);
}
public void clearNotifications() {
// TODO: make it happen
}
}

View file

@ -2,7 +2,7 @@
<resources>
<string name="app_name" translatable="false">Tusky</string>
<string name="app_website" translatable="false">https://tusky.keylesspalace.com</string>
<string name="tusky_api_url" translatable="false">https://tuskynotifier.keylesspalace.com</string>
<string name="tusky_api_url" translatable="false">tcp://tuskyapi.keylesspalace.com</string>
<string name="tusky_api_keystore_password" translatable="false">your_password_here</string>
<string name="oauth_scheme" translatable="false">oauth2redirect</string>