-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
287 changed files
with
21,876 additions
and
2,227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
TMessagesProj/src/main/java/org/telegram/messenger/ChatsWidgetProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package org.telegram.messenger; | ||
|
||
import android.app.Activity; | ||
import android.app.PendingIntent; | ||
import android.appwidget.AppWidgetManager; | ||
import android.appwidget.AppWidgetProvider; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.widget.RemoteViews; | ||
|
||
import org.telegram.ui.EditWidgetActivity; | ||
import org.telegram.ui.LaunchActivity; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ChatsWidgetProvider extends AppWidgetProvider { | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
super.onReceive(context, intent); | ||
} | ||
|
||
@Override | ||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | ||
super.onUpdate(context, appWidgetManager, appWidgetIds); | ||
for (int i = 0; i < appWidgetIds.length; i++) { | ||
int appWidgetId = appWidgetIds[i]; | ||
updateWidget(context, appWidgetManager, appWidgetId, false); | ||
} | ||
} | ||
|
||
@Override | ||
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) { | ||
updateWidget(context, appWidgetManager, appWidgetId, true); | ||
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions); | ||
} | ||
|
||
@Override | ||
public void onDeleted(Context context, int[] appWidgetIds) { | ||
super.onDeleted(context, appWidgetIds); | ||
SharedPreferences preferences = context.getSharedPreferences("shortcut_widget", Activity.MODE_PRIVATE); | ||
SharedPreferences.Editor editor = preferences.edit(); | ||
for (int a = 0; a < appWidgetIds.length; a++) { | ||
int accountId = preferences.getInt("account" + appWidgetIds[a], -1); | ||
if (accountId >= 0) { | ||
AccountInstance accountInstance = AccountInstance.getInstance(accountId); | ||
accountInstance.getMessagesStorage().clearWidgetDialogs(appWidgetIds[a]); | ||
} | ||
editor.remove("account" + appWidgetIds[a]); | ||
editor.remove("type" + appWidgetIds[a]); | ||
editor.remove("deleted" + appWidgetIds[a]); | ||
} | ||
editor.commit(); | ||
} | ||
|
||
private static int getCellsForSize(int size) { | ||
int n = 2; | ||
while (70 * n - 30 < size) { | ||
++n; | ||
} | ||
return n - 1; | ||
} | ||
|
||
public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, boolean edit) { | ||
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId); | ||
int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT); | ||
int rows = getCellsForSize(minHeight); | ||
|
||
Intent intent2 = new Intent(context, ChatsWidgetService.class); | ||
intent2.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); | ||
intent2.setData(Uri.parse(intent2.toUri(Intent.URI_INTENT_SCHEME))); | ||
|
||
SharedPreferences preferences = context.getSharedPreferences("shortcut_widget", Activity.MODE_PRIVATE); | ||
boolean deleted = preferences.getBoolean("deleted" + appWidgetId, false); | ||
int id; | ||
if (!deleted) { | ||
int accountId = preferences.getInt("account" + appWidgetId, -1); | ||
ArrayList<Long> selectedDialogs = new ArrayList<>(); | ||
if (accountId >= 0) { | ||
AccountInstance.getInstance(accountId).getMessagesStorage().getWidgetDialogIds(appWidgetId, EditWidgetActivity.TYPE_CHATS, selectedDialogs, null, null, false); | ||
} | ||
|
||
if (rows == 1 || selectedDialogs.size() <= 1) { | ||
id = R.layout.shortcut_widget_layout_1; | ||
} else if (rows == 2 || selectedDialogs.size() <= 2) { | ||
id = R.layout.shortcut_widget_layout_2; | ||
} else if (rows == 3 || selectedDialogs.size() <= 3) { | ||
id = R.layout.shortcut_widget_layout_3; | ||
} else { | ||
id = R.layout.shortcut_widget_layout_4; | ||
} | ||
} else { | ||
id = R.layout.shortcut_widget_layout_1; | ||
} | ||
RemoteViews rv = new RemoteViews(context.getPackageName(), id); | ||
rv.setRemoteAdapter(appWidgetId, R.id.list_view, intent2); | ||
rv.setEmptyView(R.id.list_view, R.id.empty_view); | ||
|
||
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); | ||
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); | ||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
intent.addCategory(Intent.CATEGORY_LAUNCHER); | ||
PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
|
||
rv.setPendingIntentTemplate(R.id.list_view, contentIntent); | ||
appWidgetManager.updateAppWidget(appWidgetId, rv); | ||
if (edit) { | ||
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.list_view); | ||
} | ||
} | ||
} |
Oops, something went wrong.