mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-29 16:09:22 +01:00
improved notification
use acra temporarily
This commit is contained in:
parent
2eed865318
commit
6de9da0338
@ -64,6 +64,9 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
|
||||
public static final String PROTOCOL_TWIDERE = SCHEME_TWIDERE + "://";
|
||||
|
||||
public static final String AUTHORITY_USER = "user";
|
||||
public static final String AUTHORITY_HOME = "home";
|
||||
public static final String AUTHORITY_MENTIONS = "mentions";
|
||||
public static final String AUTHORITY_DIRECT_MESSAGES = "direct_messages";
|
||||
public static final String AUTHORITY_USERS = "users";
|
||||
public static final String AUTHORITY_USER_TIMELINE = "user_timeline";
|
||||
public static final String AUTHORITY_USER_MEDIA_TIMELINE = "user_media_timeline";
|
||||
@ -232,7 +235,11 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
|
||||
public static final String TAB_TYPE_ACTIVITIES_ABOUT_ME = "activities_about_me";
|
||||
public static final String TAB_TYPE_ACTIVITIES_BY_FRIENDS = "activities_by_friends";
|
||||
public static final String TAB_TYPE_RETWEETS_OF_ME = "retweets_of_me";
|
||||
public static final String TAB_TYPE_STAGGERED_HOME_TIMELINE = "staggered_home_timeline";
|
||||
|
||||
|
||||
public static final int TAB_CODE_HOME_TIMELINE = 1;
|
||||
public static final int TAB_CODE_MENTIONS_TIMELINE = 2;
|
||||
public static final int TAB_CODE_DIRECT_MESSAGES = 4;
|
||||
|
||||
public static final int TWITTER_MAX_IMAGE_SIZE = 3145728;
|
||||
public static final int TWITTER_MAX_IMAGE_WIDTH = 1024;
|
||||
|
@ -72,6 +72,7 @@ dependencies {
|
||||
compile 'com.pnikosis:materialish-progress:1.4'
|
||||
compile 'com.squareup.okhttp:okhttp:2.3.0'
|
||||
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.2'
|
||||
compile 'ch.acra:acra:4.5.0'
|
||||
compile 'com.github.mariotaku:MessageBubbleView:1.0'
|
||||
compile 'com.github.mariotaku:DragSortListView:0.6.1'
|
||||
compile 'com.github.mariotaku:SlidingMenu:1.3'
|
||||
@ -83,5 +84,5 @@ dependencies {
|
||||
compile project(':twidere.component.common')
|
||||
compile project(':twidere.component.nyan')
|
||||
compile fileTree(dir: 'libs/main', include: ['*.jar'])
|
||||
googleCompile fileTree(dir: 'libs/google', include: ['*.jar'])
|
||||
// googleCompile fileTree(dir: 'libs/google', include: ['*.jar'])
|
||||
}
|
Binary file not shown.
@ -19,18 +19,9 @@
|
||||
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import com.google.android.youtube.player.YouTubeInitializationResult;
|
||||
import com.google.android.youtube.player.YouTubePlayer;
|
||||
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
|
||||
import com.google.android.youtube.player.YouTubePlayer.Provider;
|
||||
import com.google.android.youtube.player.YouTubePlayerSupportFragment;
|
||||
|
||||
import org.mariotaku.twidere.model.ParcelableStatus.ParcelableCardEntity;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus.ParcelableCardEntity.ParcelableValueItem;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/1/1.
|
||||
|
@ -98,6 +98,7 @@ import org.mariotaku.twidere.util.FlymeUtils;
|
||||
import org.mariotaku.twidere.util.HotKeyHandler;
|
||||
import org.mariotaku.twidere.util.MathUtils;
|
||||
import org.mariotaku.twidere.util.MultiSelectEventHandler;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UnreadCountUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
@ -119,7 +120,6 @@ import edu.tsinghua.spice.Utilies.SpiceProfilingUtil;
|
||||
import edu.ucdavis.earlybird.ProfilingUtil;
|
||||
|
||||
import static org.mariotaku.twidere.util.CompareUtils.classEquals;
|
||||
import static org.mariotaku.twidere.util.CustomTabUtils.getAddedTabPosition;
|
||||
import static org.mariotaku.twidere.util.Utils.cleanDatabasesByItemLimit;
|
||||
import static org.mariotaku.twidere.util.Utils.getAccountIds;
|
||||
import static org.mariotaku.twidere.util.Utils.getDefaultAccountId;
|
||||
@ -343,7 +343,6 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
|
||||
sendBroadcast(new Intent(BROADCAST_HOME_ACTIVITY_ONCREATE));
|
||||
final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
|
||||
mTabDisplayOption = getTabDisplayOptionInt(this);
|
||||
final int initialTabPosition = handleIntent(intent, savedInstanceState == null);
|
||||
|
||||
mColorStatusFrameLayout.setOnFitSystemWindowsListener(this);
|
||||
ThemeUtils.applyBackground(mTabIndicator);
|
||||
@ -361,7 +360,7 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
|
||||
mActionsButton.setOnClickListener(this);
|
||||
mActionsButton.setOnLongClickListener(this);
|
||||
mEmptyTabHint.setOnClickListener(this);
|
||||
setTabPosition(initialTabPosition);
|
||||
|
||||
setupSlidingMenu();
|
||||
setupBars();
|
||||
showDataProfilingRequest();
|
||||
@ -380,6 +379,9 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
|
||||
}
|
||||
mPagerPosition = Float.NaN;
|
||||
setupHomeTabs();
|
||||
|
||||
final int initialTabPosition = handleIntent(intent, savedInstanceState == null);
|
||||
setTabPosition(initialTabPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -607,9 +609,9 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(final Intent intent) {
|
||||
final int tab_position = handleIntent(intent, false);
|
||||
if (tab_position >= 0) {
|
||||
mViewPager.setCurrentItem(MathUtils.clamp(tab_position, mPagerAdapter.getCount(), 0));
|
||||
final int tabPosition = handleIntent(intent, false);
|
||||
if (tabPosition >= 0) {
|
||||
mViewPager.setCurrentItem(MathUtils.clamp(tabPosition, mPagerAdapter.getCount(), 0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -683,8 +685,21 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
|
||||
mTwitterWrapper.refreshAll();
|
||||
}
|
||||
|
||||
final int tab = intent.getIntExtra(EXTRA_INITIAL_TAB, -1);
|
||||
final int initialTab = tab != -1 ? tab : getAddedTabPosition(this, intent.getStringExtra(EXTRA_TAB_TYPE));
|
||||
final Uri uri = intent.getData();
|
||||
final String tabType = uri != null ? Utils.matchTabType(uri) : null;
|
||||
int initialTab = -1, initalTabFallback;
|
||||
if (tabType != null) {
|
||||
final long accountId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID));
|
||||
for (int i = mPagerAdapter.getCount() - 1; i > -1; i--) {
|
||||
final SupportTabSpec tab = mPagerAdapter.getTab(i);
|
||||
if (tabType.equals(tab.type)) {
|
||||
initialTab = i;
|
||||
if (hasAccountId(tab.args, accountId)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (initialTab != -1 && mViewPager != null) {
|
||||
// clearNotification(initial_tab);
|
||||
}
|
||||
@ -696,6 +711,16 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
|
||||
return initialTab;
|
||||
}
|
||||
|
||||
private boolean hasAccountId(Bundle args, long accountId) {
|
||||
if (args == null) return false;
|
||||
if (args.containsKey(EXTRA_ACCOUNT_ID)) {
|
||||
return args.getLong(EXTRA_ACCOUNT_ID) == accountId;
|
||||
} else if (args.containsKey(EXTRA_ACCOUNT_IDS)) {
|
||||
return ArrayUtils.contains(args.getLongArray(EXTRA_ACCOUNT_IDS), accountId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasActivatedTask() {
|
||||
if (mTwitterWrapper == null) return false;
|
||||
return mTwitterWrapper.hasActivatedTask();
|
||||
@ -720,10 +745,10 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
|
||||
}
|
||||
|
||||
private void setTabPosition(final int initial_tab) {
|
||||
final boolean remember_position = mPreferences.getBoolean(KEY_REMEMBER_POSITION, true);
|
||||
final boolean rememberPosition = mPreferences.getBoolean(KEY_REMEMBER_POSITION, true);
|
||||
if (initial_tab >= 0) {
|
||||
mViewPager.setCurrentItem(MathUtils.clamp(initial_tab, mPagerAdapter.getCount(), 0));
|
||||
} else if (remember_position) {
|
||||
} else if (rememberPosition) {
|
||||
final int position = mPreferences.getInt(KEY_SAVED_TAB_POSITION, 0);
|
||||
mViewPager.setCurrentItem(MathUtils.clamp(position, mPagerAdapter.getCount(), 0));
|
||||
}
|
||||
|
@ -42,18 +42,20 @@ import com.nostra13.universalimageloader.core.download.ImageDownloader;
|
||||
import com.nostra13.universalimageloader.utils.L;
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import org.acra.ReportingInteractionMode;
|
||||
import org.acra.annotation.ReportsCrashes;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.activity.MainActivity;
|
||||
import org.mariotaku.twidere.activity.MainHondaJOJOActivity;
|
||||
import org.mariotaku.twidere.service.RefreshService;
|
||||
import org.mariotaku.twidere.util.AsyncTaskManager;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.BugReporter;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.MessagesManager;
|
||||
import org.mariotaku.twidere.util.MultiSelectManager;
|
||||
import org.mariotaku.twidere.util.ReadStateManager;
|
||||
import org.mariotaku.twidere.util.StrictModeUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.VideoLoader;
|
||||
import org.mariotaku.twidere.util.content.TwidereSQLiteOpenHelper;
|
||||
@ -74,6 +76,7 @@ import static org.mariotaku.twidere.util.Utils.initAccountColor;
|
||||
import static org.mariotaku.twidere.util.Utils.startRefreshServiceIfNeeded;
|
||||
import static org.mariotaku.twidere.util.Utils.startUsageStatisticsServiceIfNeeded;
|
||||
|
||||
@ReportsCrashes(formKey = "", mode = ReportingInteractionMode.SILENT)
|
||||
public class TwidereApplication extends MultiDexApplication implements Constants,
|
||||
OnSharedPreferenceChangeListener {
|
||||
|
||||
@ -199,10 +202,11 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
BugReporter.init(this);
|
||||
if (Utils.isDebugBuild()) {
|
||||
StrictModeUtils.detectAllVmPolicy();
|
||||
}
|
||||
setTheme(ThemeUtils.getThemeResource(this));
|
||||
// setTheme(ThemeUtils.getThemeResource(this));
|
||||
super.onCreate();
|
||||
mHandler = new Handler();
|
||||
mMessageBus = new Bus();
|
||||
@ -226,9 +230,7 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
|
||||
migrateUsageStatisticsPreferences();
|
||||
|
||||
startUsageStatisticsServiceIfNeeded(this);
|
||||
startRefreshServiceIfNeeded(this);
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.internal.view.SupportMenuInflater;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.ActionMenuView.OnMenuItemClickListener;
|
||||
import android.support.v7.widget.FixedLinearLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.Adapter;
|
||||
@ -91,7 +92,6 @@ import org.mariotaku.twidere.menu.SupportAccountActionProvider;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
import org.mariotaku.twidere.util.CompareUtils;
|
||||
import android.support.v7.widget.FixedLinearLayoutManager;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TransitionUtils;
|
||||
@ -100,6 +100,7 @@ import org.mariotaku.twidere.util.content.SupportFragmentReloadCursorObserver;
|
||||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -207,9 +208,7 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
|
||||
}
|
||||
}
|
||||
mAccountsAdapter.setAccounts(accounts);
|
||||
if (mAccountsAdapter.getSelectedAccountId() <= 0) {
|
||||
mAccountsAdapter.setSelectedAccountId(mPreferences.getLong(KEY_DEFAULT_ACCOUNT_ID, defaultId));
|
||||
}
|
||||
mAccountsAdapter.setSelectedAccountId(mPreferences.getLong(KEY_DEFAULT_ACCOUNT_ID, defaultId));
|
||||
mAccountActionProvider.setAccounts(accounts);
|
||||
mAccountActionProvider.setSelectedAccountIds(ArrayUtils.toPrimitive(activatedIds.toArray(new Long[activatedIds.size()])));
|
||||
|
||||
@ -604,7 +603,6 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
|
||||
private final LayoutInflater mInflater;
|
||||
private final MediaLoaderWrapper mImageLoader;
|
||||
private final AccountsDashboardFragment mFragment;
|
||||
private ParcelableAccount[] mAccounts;
|
||||
private ParcelableAccount[] mInternalAccounts;
|
||||
|
||||
AccountSelectorAdapter(Context context, AccountsDashboardFragment fragment) {
|
||||
@ -622,15 +620,12 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
|
||||
}
|
||||
|
||||
public void setAccounts(ParcelableAccount[] accounts) {
|
||||
mAccounts = accounts;
|
||||
if (accounts != null) {
|
||||
final ParcelableAccount[] previousAccounts = mInternalAccounts;
|
||||
mInternalAccounts = new ParcelableAccount[accounts.length];
|
||||
int tempIdx = 0;
|
||||
final List<ParcelableAccount> tempList = new ArrayList<>();
|
||||
for (ParcelableAccount account : accounts) {
|
||||
tempList.add(account);
|
||||
}
|
||||
Collections.addAll(tempList, accounts);
|
||||
if (previousAccounts != null) {
|
||||
for (ParcelableAccount previousAccount : previousAccounts) {
|
||||
final int idx = indexOfAccount(tempList, previousAccount.account_id);
|
||||
|
@ -898,10 +898,16 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
||||
|
||||
// Setup on click intent
|
||||
final Intent homeIntent = new Intent(context, HomeActivity.class);
|
||||
final Uri.Builder homeLinkBuilder = new Uri.Builder();
|
||||
homeLinkBuilder.scheme(SCHEME_TWIDERE);
|
||||
homeLinkBuilder.authority(AUTHORITY_HOME);
|
||||
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
|
||||
homeIntent.setData(homeLinkBuilder.build());
|
||||
final PendingIntent clickIntent = PendingIntent.getActivity(context, 0, homeIntent, 0);
|
||||
|
||||
// Setup notification
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||
builder.setAutoCancel(true);
|
||||
builder.setSmallIcon(R.drawable.ic_stat_twitter);
|
||||
builder.setTicker(notificationTitle);
|
||||
builder.setContentTitle(notificationTitle);
|
||||
@ -983,10 +989,16 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
||||
|
||||
// Setup on click intent
|
||||
final Intent homeIntent = new Intent(context, HomeActivity.class);
|
||||
final Uri.Builder homeLinkBuilder = new Uri.Builder();
|
||||
homeLinkBuilder.scheme(SCHEME_TWIDERE);
|
||||
homeLinkBuilder.authority(AUTHORITY_MENTIONS);
|
||||
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
|
||||
homeIntent.setData(homeLinkBuilder.build());
|
||||
final PendingIntent clickIntent = PendingIntent.getActivity(context, 0, homeIntent, 0);
|
||||
|
||||
// Setup notification
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||
builder.setAutoCancel(true);
|
||||
builder.setSmallIcon(R.drawable.ic_stat_mention);
|
||||
builder.setTicker(notificationTitle);
|
||||
builder.setContentTitle(notificationTitle);
|
||||
@ -1105,10 +1117,16 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
||||
|
||||
// Setup on click intent
|
||||
final Intent homeIntent = new Intent(context, HomeActivity.class);
|
||||
final Uri.Builder homeLinkBuilder = new Uri.Builder();
|
||||
homeLinkBuilder.scheme(SCHEME_TWIDERE);
|
||||
homeLinkBuilder.authority(AUTHORITY_DIRECT_MESSAGES);
|
||||
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
|
||||
homeIntent.setData(homeLinkBuilder.build());
|
||||
final PendingIntent clickIntent = PendingIntent.getActivity(context, 0, homeIntent, 0);
|
||||
|
||||
// Setup notification
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||
builder.setAutoCancel(true);
|
||||
builder.setSmallIcon(R.drawable.ic_stat_direct_message);
|
||||
builder.setTicker(notificationTitle);
|
||||
builder.setContentTitle(notificationTitle);
|
||||
|
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.text.TextUtils;
|
||||
import android.util.JsonReader;
|
||||
import android.util.Log;
|
||||
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Request.Builder;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.Response;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ErrorReporter;
|
||||
import org.acra.ReportField;
|
||||
import org.acra.collector.CrashReportData;
|
||||
import org.acra.sender.ReportSender;
|
||||
import org.acra.sender.ReportSenderException;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Locale;
|
||||
import java.util.Scanner;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/3/28.
|
||||
*/
|
||||
public class BugReporter implements Constants {
|
||||
public static void init(TwidereApplication application) {
|
||||
ACRA.init(application);
|
||||
final ErrorReporter reporter = ACRA.getErrorReporter();
|
||||
reporter.setReportSender(new GitHubIssueReportSender());
|
||||
}
|
||||
|
||||
public static class GitHubIssueReportSender implements ReportSender {
|
||||
|
||||
private static final String AUTH_TOKEN = "208aacee0f51338a85ba5e9e3da54859981456ca";
|
||||
private static final String USER_REPO = "mariotaku-bugreport/Twidere-Android.bugreport.test";
|
||||
|
||||
@Override
|
||||
public void send(CrashReportData report) throws ReportSenderException {
|
||||
final String stackTrace = report.getProperty(ReportField.STACK_TRACE);
|
||||
final StringBuilder bodyBuilder = new StringBuilder();
|
||||
buildIssueBody(report, bodyBuilder);
|
||||
final Scanner scanner = new Scanner(stackTrace);
|
||||
final String messageLine = scanner.nextLine();
|
||||
final String recentLine = scanner.nextLine();
|
||||
final String titleContent = messageLine + " " + recentLine;
|
||||
scanner.close();
|
||||
final StringBuilder titleBuilder = new StringBuilder();
|
||||
final CRC32 crc32 = new CRC32();
|
||||
crc32.update(titleContent.getBytes(Charset.defaultCharset()));
|
||||
final String checksum = Long.toHexString(crc32.getValue());
|
||||
titleBuilder.append(checksum);
|
||||
titleBuilder.append(" ");
|
||||
titleBuilder.append(titleContent);
|
||||
final JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("title", titleBuilder.toString());
|
||||
json.put("body", bodyBuilder.toString());
|
||||
} catch (JSONException e) {
|
||||
throw new ReportSenderException("Error processing report json", e);
|
||||
}
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
final Request.Builder searchIssueBuilder = new Request.Builder();
|
||||
final String query = String.format(Locale.ROOT, "%s repo:%s", checksum, USER_REPO);
|
||||
final Uri.Builder searchIssueUrlBuilder = Uri.parse("https://api.github.com/search/issues").buildUpon();
|
||||
searchIssueUrlBuilder.appendQueryParameter("q", query);
|
||||
searchIssueBuilder.url(searchIssueUrlBuilder.build().toString());
|
||||
authorizeRequest(searchIssueBuilder);
|
||||
try {
|
||||
final Response response = client.newCall(searchIssueBuilder.build()).execute();
|
||||
final JsonReader jsonReader = new JsonReader(response.body().charStream());
|
||||
boolean isDuplicate = false;
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
if ("total_count".equals(jsonReader.nextName())) {
|
||||
isDuplicate = jsonReader.nextInt() > 0;
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
jsonReader.endObject();
|
||||
if (isDuplicate) {
|
||||
Log.d(LOGTAG, "Issue already exists");
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
final String msg = "Network error when searching issues";
|
||||
Log.w(LOGTAG, msg, e);
|
||||
throw new ReportSenderException(msg, e);
|
||||
}
|
||||
final RequestBody issueBody = RequestBody.create(MediaType.parse("application/json"), json.toString());
|
||||
final Request.Builder createIssueBuilder = new Request.Builder();
|
||||
createIssueBuilder.url(String.format(Locale.ROOT, "https://api.github.com/repos/%s/issues", USER_REPO));
|
||||
createIssueBuilder.post(issueBody);
|
||||
authorizeRequest(createIssueBuilder);
|
||||
try {
|
||||
final Response response = client.newCall(createIssueBuilder.build()).execute();
|
||||
final String location = response.header("Location");
|
||||
if (!TextUtils.isEmpty(location)) {
|
||||
Log.d(LOGTAG, "Issue created at " + location);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
final String msg = "Network error when sending error report";
|
||||
Log.w(LOGTAG, msg, e);
|
||||
throw new ReportSenderException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildIssueBody(CrashReportData report, StringBuilder bodyBuilder) {
|
||||
bodyBuilder.append("**Application Version**: ");
|
||||
bodyBuilder.append(report.getProperty(ReportField.APP_VERSION_NAME));
|
||||
bodyBuilder.append(" (");
|
||||
bodyBuilder.append(report.getProperty(ReportField.APP_VERSION_CODE));
|
||||
bodyBuilder.append(")\n\n");
|
||||
bodyBuilder.append("**Device Information**: ");
|
||||
bodyBuilder.append(Build.MODEL);
|
||||
bodyBuilder.append(" (");
|
||||
bodyBuilder.append(Build.PRODUCT);
|
||||
bodyBuilder.append(", ");
|
||||
bodyBuilder.append(Build.BRAND);
|
||||
bodyBuilder.append(")");
|
||||
bodyBuilder.append(", ");
|
||||
bodyBuilder.append("Android ");
|
||||
bodyBuilder.append(VERSION.RELEASE);
|
||||
bodyBuilder.append(" (");
|
||||
bodyBuilder.append(VERSION.SDK_INT);
|
||||
bodyBuilder.append(")\n\n");
|
||||
bodyBuilder.append("**User comment**: \n");
|
||||
bodyBuilder.append("````\n");
|
||||
bodyBuilder.append(report.getProperty(ReportField.USER_COMMENT));
|
||||
bodyBuilder.append("\n````\n");
|
||||
bodyBuilder.append("**Stack trace**: \n");
|
||||
bodyBuilder.append("````\n");
|
||||
bodyBuilder.append(report.getProperty(ReportField.STACK_TRACE));
|
||||
bodyBuilder.append("\n````");
|
||||
}
|
||||
|
||||
private void authorizeRequest(Builder builder) {
|
||||
builder.header("Authorization", "token " + AUTH_TOKEN);
|
||||
builder.header("Accept", "application/vnd.github.v3+json");
|
||||
builder.header("User-Agent", "Twidere (" + BuildConfig.VERSION_NAME + ")");
|
||||
}
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
@ -59,8 +60,8 @@ import java.util.Map.Entry;
|
||||
import static org.mariotaku.twidere.util.CompareUtils.classEquals;
|
||||
|
||||
public class CustomTabUtils implements Constants {
|
||||
private static final HashMap<String, CustomTabConfiguration> CUSTOM_TABS_CONFIGURATION_MAP = new HashMap<String, CustomTabConfiguration>();
|
||||
private static final HashMap<String, Integer> CUSTOM_TABS_ICON_NAME_MAP = new HashMap<String, Integer>();
|
||||
private static final HashMap<String, CustomTabConfiguration> CUSTOM_TABS_CONFIGURATION_MAP = new HashMap<>();
|
||||
private static final HashMap<String, Integer> CUSTOM_TABS_ICON_NAME_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
CUSTOM_TABS_CONFIGURATION_MAP.put(TAB_TYPE_HOME_TIMELINE, new CustomTabConfiguration(
|
||||
@ -210,7 +211,7 @@ public class CustomTabUtils implements Constants {
|
||||
}
|
||||
|
||||
public static HashMap<String, CustomTabConfiguration> getConfiguraionMap() {
|
||||
return new HashMap<String, CustomTabConfiguration>(CUSTOM_TABS_CONFIGURATION_MAP);
|
||||
return new HashMap<>(CUSTOM_TABS_CONFIGURATION_MAP);
|
||||
}
|
||||
|
||||
public static List<SupportTabSpec> getHomeTabs(final Context context) {
|
||||
@ -218,7 +219,7 @@ public class CustomTabUtils implements Constants {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, Tabs.DEFAULT_SORT_ORDER);
|
||||
if (cur == null) return Collections.emptyList();
|
||||
final ArrayList<SupportTabSpec> tabs = new ArrayList<SupportTabSpec>();
|
||||
final ArrayList<SupportTabSpec> tabs = new ArrayList<>();
|
||||
cur.moveToFirst();
|
||||
final int idxName = cur.getColumnIndex(Tabs.NAME), idxIcon = cur.getColumnIndex(Tabs.ICON), idxType = cur
|
||||
.getColumnIndex(Tabs.TYPE), idxArguments = cur.getColumnIndex(Tabs.ARGUMENTS), idxExtras = cur
|
||||
@ -243,7 +244,7 @@ public class CustomTabUtils implements Constants {
|
||||
}
|
||||
|
||||
public static HashMap<String, Integer> getIconMap() {
|
||||
return new HashMap<String, Integer>(CUSTOM_TABS_ICON_NAME_MAP);
|
||||
return new HashMap<>(CUSTOM_TABS_ICON_NAME_MAP);
|
||||
}
|
||||
|
||||
public static CustomTabConfiguration getTabConfiguration(final String key) {
|
||||
@ -259,7 +260,7 @@ public class CustomTabUtils implements Constants {
|
||||
if (res == null) return null;
|
||||
if (iconObj instanceof Integer) {
|
||||
try {
|
||||
return res.getDrawable((Integer) iconObj);
|
||||
return ResourcesCompat.getDrawable(res, (Integer) iconObj, null);
|
||||
} catch (final Resources.NotFoundException e) {
|
||||
// Ignore.
|
||||
}
|
||||
@ -271,7 +272,7 @@ public class CustomTabUtils implements Constants {
|
||||
final Bitmap b = getTabIconFromFile((File) iconObj, res);
|
||||
if (b != null) return new BitmapDrawable(res, b);
|
||||
}
|
||||
return res.getDrawable(R.drawable.ic_action_list);
|
||||
return ResourcesCompat.getDrawable(res, R.drawable.ic_action_list, null);
|
||||
}
|
||||
|
||||
public static Bitmap getTabIconFromFile(final File file, final Resources res) {
|
||||
|
@ -270,6 +270,7 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
public static final Pattern PATTERN_RESOURCE_IDENTIFIER = Pattern.compile("@([\\w_]+)/([\\w_]+)");
|
||||
private static final UriMatcher CONTENT_PROVIDER_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
private static final UriMatcher LINK_HANDLER_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
private static final UriMatcher HOME_TABS_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
|
||||
static {
|
||||
CONTENT_PROVIDER_URI_MATCHER.addURI(TwidereDataStore.AUTHORITY, Accounts.CONTENT_PATH,
|
||||
@ -379,6 +380,9 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
LINK_HANDLER_URI_MATCHER.addURI(AUTHORITY_SEARCH, null, LINK_ID_SEARCH);
|
||||
LINK_HANDLER_URI_MATCHER.addURI(AUTHORITY_MUTES_USERS, null, LINK_ID_MUTES_USERS);
|
||||
|
||||
HOME_TABS_URI_MATCHER.addURI(AUTHORITY_HOME, null, CustomTabUtils.TAB_CODE_HOME_TIMELINE);
|
||||
HOME_TABS_URI_MATCHER.addURI(AUTHORITY_MENTIONS, null, CustomTabUtils.TAB_CODE_MENTIONS_TIMELINE);
|
||||
HOME_TABS_URI_MATCHER.addURI(AUTHORITY_DIRECT_MESSAGES, null, CustomTabUtils.TAB_CODE_DIRECT_MESSAGES);
|
||||
}
|
||||
|
||||
private static LongSparseArray<Integer> sAccountColors = new LongSparseArray<>();
|
||||
@ -2829,6 +2833,31 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
return LINK_HANDLER_URI_MATCHER.match(uri);
|
||||
}
|
||||
|
||||
|
||||
public static int matchTabCode(final Uri uri) {
|
||||
return HOME_TABS_URI_MATCHER.match(uri);
|
||||
}
|
||||
|
||||
|
||||
public static String matchTabType(final Uri uri) {
|
||||
return getTabType(matchTabCode(uri));
|
||||
}
|
||||
|
||||
public static String getTabType(final int code) {
|
||||
switch (code) {
|
||||
case TAB_CODE_HOME_TIMELINE: {
|
||||
return TAB_TYPE_HOME_TIMELINE;
|
||||
}
|
||||
case TAB_CODE_MENTIONS_TIMELINE: {
|
||||
return TAB_TYPE_MENTIONS_TIMELINE;
|
||||
}
|
||||
case TAB_CODE_DIRECT_MESSAGES: {
|
||||
return TAB_TYPE_DIRECT_MESSAGES;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void openMessageConversation(final FragmentActivity activity, final long accountId,
|
||||
final long recipientId) {
|
||||
if (activity == null) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user