Переглянути джерело

More修改,新闻H5跳转

Huping 1 рік тому
батько
коміт
905a01a586

+ 34 - 16
TMessagesProj/src/main/AndroidManifest.xml

@@ -63,7 +63,7 @@
     <uses-permission android:name="android.permission.BLUETOOTH" />
     <uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
     <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
-<!--    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />-->
+    <!--    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />-->
     <uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
     <uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
     <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />
@@ -204,6 +204,10 @@
                 <data
                     android:host="t.me"
                     android:scheme="https" />
+                <!--                <data-->
+                <!--                    android:host="resolve"-->
+                <!--                    android:scheme="cricdit" />-->
+
             </intent-filter>
             <intent-filter
                 android:icon="@drawable/launcher_icon"
@@ -215,6 +219,20 @@
                 <category android:name="android.intent.category.DEFAULT" />
 
                 <data android:scheme="tg" />
+
+            </intent-filter>
+            <intent-filter
+                android:icon="@drawable/launcher_icon"
+                android:priority="1"
+                android:roundIcon="@drawable/launcher_icon">
+
+                <data android:scheme="cricdit" />
+
+                <action android:name="android.intent.action.VIEW" />
+
+                <category android:name="android.intent.category.BROWSABLE" />
+                <category android:name="android.intent.category.DEFAULT" />
+
             </intent-filter>
             <intent-filter>
                 <action android:name="org.telegram.messenger.CREATE_STICKER_PACK" />
@@ -718,34 +736,34 @@
             android:value="2.5" />
 
         <activity
-            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
-            android:name="org.telegram.onecric.ui.activity.CricketDetailActivity"/>
+            android:name="org.telegram.onecric.ui.activity.CricketDetailActivity"
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
         <activity
-            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
-            android:name="org.telegram.onecric.ui.activity.CricketInnerActivity"/>
+            android:name="org.telegram.onecric.ui.activity.CricketInnerActivity"
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
         <activity
-            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
-            android:name="org.telegram.onecric.ui.activity.CricketTeamsActivity"/>
+            android:name="org.telegram.onecric.ui.activity.CricketTeamsActivity"
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
         <activity
-            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
-            android:name="org.telegram.onecric.ui.activity.PlayerProfileActivity"/>
+            android:name="org.telegram.onecric.ui.activity.PlayerProfileActivity"
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
         <activity
-            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
-            android:name="org.telegram.onecric.ui.activity.CricketStatsActivity"/>
+            android:name="org.telegram.onecric.ui.activity.CricketStatsActivity"
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
         <activity
-            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
-            android:name="org.telegram.onecric.ui.activity.PlayerStatsActivity"/>
+            android:name="org.telegram.onecric.ui.activity.PlayerStatsActivity"
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
         <activity
-            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
-            android:name="org.telegram.onecric.ui.activity.TeamComparisonActivity"/>
+            android:name="org.telegram.onecric.ui.activity.TeamComparisonActivity"
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
-        <service android:name="org.telegram.cricdit.service.SyncDataService"/>
+        <service android:name="org.telegram.cricdit.service.SyncDataService" />
 
     </application>
 

+ 147 - 31
TMessagesProj/src/main/java/org/telegram/cricdit/ui/MoreGroupFragment.java

@@ -19,15 +19,20 @@ import org.telegram.cricdit.mvp.MoreGroupPresenter;
 import org.telegram.cricdit.mvp.MoreGroupView;
 import org.telegram.cricdit.utils.ToastUtil;
 import org.telegram.messenger.AndroidUtilities;
+import org.telegram.messenger.ChatObject;
 import org.telegram.messenger.LocaleController;
 import org.telegram.messenger.MessagesController;
 import org.telegram.messenger.MessagesStorage;
 import org.telegram.messenger.R;
+import org.telegram.messenger.UserConfig;
 import org.telegram.tgnet.ConnectionsManager;
 import org.telegram.tgnet.TLObject;
 import org.telegram.tgnet.TLRPC;
+import org.telegram.ui.ActionBar.AlertDialog;
 import org.telegram.ui.ActionBar.BaseFragment;
 import org.telegram.ui.ChatActivity;
+import org.telegram.ui.Components.JoinGroupAlert;
+import org.telegram.ui.LoginActivity;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -41,6 +46,7 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
     private SmartRefreshLayout mRefreshLayout;
     private MoreGroupAdapter mAdapter;
     private List<MoreGroupBean.ListDTO> mMoreGroupBeanList;
+    private AlertDialog alertDialog;
 
 
     public MoreGroupFragment(BaseFragment fragment) {
@@ -55,6 +61,8 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
     private void initView(View view) {
         mMoreGroupBeanList = new ArrayList<>();
 
+        alertDialog = new AlertDialog(mFragment.getParentActivity(), 3);
+
         mRefreshLayout = view.findViewById(R.id.more_group_refresh_layout);
         mRefreshLayout.setEnableLoadMore(false);
 
@@ -67,9 +75,30 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
         View inflate = LayoutInflater.from(mFragment.getContext()).inflate(R.layout.layout_empty_view, null, false);
         mAdapter.setEmptyView(inflate);
         mAdapter.setOnItemClickListener((adapter, view1, position) -> {
-            List<MoreGroupBean.ListDTO> data = mAdapter.getData();
-            if (data != null && data.size() > 0) {
-                jumpToChat(data.get(position).public_link, Long.parseLong(data.get(position).group_id));
+            if (UserConfig.getInstance(0).isClientActivated()) {
+                MoreGroupBean.ListDTO groupData = mAdapter.getData().get(position);
+                alertDialog.show();
+                if (!TextUtils.isEmpty(groupData.private_link)) {
+                    newSkipUrl(groupData.private_link);
+                } else {
+                    if (!TextUtils.isEmpty(groupData.public_link)) {
+                        if (groupData.public_link.startsWith("https://t.me/")) {
+                            newSkipUrl(groupData.public_link);
+                        } else {
+                            newSkipUrl("https://t.me/" + groupData.public_link);
+                        }
+                    } else {
+                        if (alertDialog != null) {
+                            alertDialog.dismiss();
+                        }
+                        ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString(R.string.CdExpiredGroup));
+                    }
+                }
+            } else {
+                if (alertDialog != null) {
+                    alertDialog.dismiss();
+                }
+                mFragment.presentFragment(new LoginActivity());
             }
         });
         mRecyclerView.setAdapter(mAdapter);
@@ -106,30 +135,92 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
         return view;
     }
 
-    public void jumpToChat(String publicLink, long groupId) {
-        TLObject req;
-        if (!TextUtils.isEmpty(publicLink)) {
-            TLRPC.Chat chatStor = MessagesController.getInstance(0).getChat(groupId);
-            if (chatStor == null) {
-                String publickLink = "";
-                if (publicLink.startsWith(Constants.TEL_NORMAL_URL_PREFIX)) {
-                    publickLink = publicLink.split(Constants.TEL_NORMAL_URL_PREFIX)[1];
-                } else {
-                    publickLink = publicLink;
-                }
+//    public void jumpToChat(String publicLink, long groupId) {
+//        TLObject req;
+//        if (!TextUtils.isEmpty(publicLink)) {
+//            TLRPC.Chat chatStor = MessagesController.getInstance(0).getChat(groupId);
+//            if (chatStor == null) {
+//                String publickLink = "";
+//                if (publicLink.startsWith(Constants.TEL_NORMAL_URL_PREFIX)) {
+//                    publickLink = publicLink.split(Constants.TEL_NORMAL_URL_PREFIX)[1];
+//                } else {
+//                    publickLink = publicLink;
+//                }
+//
+//                TLRPC.TL_contacts_resolveUsername resolveUsername = new TLRPC.TL_contacts_resolveUsername();
+//                resolveUsername.username = publickLink;
+//                req = resolveUsername;
+//
+//                ConnectionsManager.getInstance(0).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
+//                    TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
+//                    if (error == null && res != null && res.chats != null) {
+//                        MessagesController.getInstance(0).putUsers(res.users, false);
+//                        MessagesController.getInstance(0).putChats(res.chats, false);
+//                        MessagesStorage.getInstance(0).putUsersAndChats(res.users, res.chats, false, true);
+//                        TLRPC.Chat chat = res.chats.get(0);
+//                        if (chat != null) {
+//                            Bundle args = new Bundle();
+//                            if (!res.chats.isEmpty()) {
+//                                args.putLong("chat_id", res.chats.get(0).id);
+//                            } else {
+//                                args.putLong("user_id", res.users.get(0).id);
+//                            }
+//                            mFragment.presentFragment(new ChatActivity(args));
+//                        } else {
+//                            if (mFragment != null && mFragment.getParentActivity() != null) {
+//                                ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString(R.string.ExpiredLink));
+//                            }
+//                        }
+//                    }
+//                }));
+//            } else {
+//                Bundle args = new Bundle();
+//                args.putLong("chat_id", chatStor.id);
+//                mFragment.presentFragment(new ChatActivity(args));
+//            }
+//        }
+//    }
 
-                TLRPC.TL_contacts_resolveUsername resolveUsername = new TLRPC.TL_contacts_resolveUsername();
-                resolveUsername.username = publickLink;
-                req = resolveUsername;
+    public void newSkipUrl(String finalWorkingText) {
+        if (finalWorkingText.contains("https://t.me/")) {
+            int index = finalWorkingText.indexOf("https://t.me/");
+            int end = finalWorkingText.indexOf(" ", index);
+            String gName;
+            String group = "";
+            if (end != -1) {
+                gName = finalWorkingText.substring(index + "https://t.me/".length(), end);
+            } else {
+                gName = finalWorkingText.substring(index + "https://t.me/".length());
+            }
+            if (gName.startsWith("+")) {
+                group = gName.replace("+", "");
+                if (AndroidUtilities.isNumeric(group)) {
+                    gName = group;
+                    group = null;
+                }
+            }
+            if (TextUtils.isEmpty(group)) {
+                if (gName != null) {
+                    TLObject req;
+                    if (AndroidUtilities.isNumeric(gName)) {
+                        TLRPC.TL_contacts_resolvePhone resolvePhone = new TLRPC.TL_contacts_resolvePhone();
+                        resolvePhone.phone = gName;
+                        req = resolvePhone;
+                    } else {
+                        TLRPC.TL_contacts_resolveUsername resolveUsername = new TLRPC.TL_contacts_resolveUsername();
+                        resolveUsername.username = gName;
+                        req = resolveUsername;
+                    }
 
-                ConnectionsManager.getInstance(0).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
-                    TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
-                    if (error == null && res != null && res.chats != null) {
-                        MessagesController.getInstance(0).putUsers(res.users, false);
-                        MessagesController.getInstance(0).putChats(res.chats, false);
-                        MessagesStorage.getInstance(0).putUsersAndChats(res.users, res.chats, false, true);
-                        TLRPC.Chat chat = res.chats.get(0);
-                        if (chat != null) {
+                    ConnectionsManager.getInstance(0).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
+                        if (alertDialog != null) {
+                            alertDialog.dismiss();
+                        }
+                        TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
+                        if (error == null && res != null && res.users != null) {
+                            MessagesController.getInstance(0).putUsers(res.users, false);
+                            MessagesController.getInstance(0).putChats(res.chats, false);
+                            MessagesStorage.getInstance(0).putUsersAndChats(res.users, res.chats, false, true);
                             Bundle args = new Bundle();
                             if (!res.chats.isEmpty()) {
                                 args.putLong("chat_id", res.chats.get(0).id);
@@ -137,18 +228,43 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
                                 args.putLong("user_id", res.users.get(0).id);
                             }
                             mFragment.presentFragment(new ChatActivity(args));
+
                         } else {
-                            if (mFragment != null && mFragment.getParentActivity() != null) {
-                                ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString(R.string.ExpiredLink));
+                            ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString("ExpiredLink", R.string.ExpiredLink));
+                        }
+                    }));
+                }
+            } else {
+                final TLRPC.TL_messages_checkChatInvite req = new TLRPC.TL_messages_checkChatInvite();
+                req.hash = group;
+                String finalGroup = group;
+                ConnectionsManager.getInstance(0).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
+                    if (alertDialog != null) {
+                        alertDialog.dismiss();
+                    }
+                    if (error == null) {
+                        TLRPC.ChatInvite invite = (TLRPC.ChatInvite) response;
+                        if (invite.chat != null && (!ChatObject.isLeftFromChat(invite.chat) || !invite.chat.kicked && (!TextUtils.isEmpty(invite.chat.username) || invite instanceof TLRPC.TL_chatInvitePeek || invite.chat.has_geo))) {
+                            MessagesController.getInstance(0).putChat(invite.chat, false);
+                            ArrayList<TLRPC.Chat> chats = new ArrayList<>();
+                            chats.add(invite.chat);
+                            MessagesStorage.getInstance(0).putUsersAndChats(null, chats, false, true);
+                            Bundle args = new Bundle();
+                            args.putLong("chat_id", invite.chat.id);
+                            mFragment.presentFragment(new ChatActivity(args));
+                        } else {
+                            if (mFragment != null) {
+                                mFragment.showDialog(new JoinGroupAlert(mFragment.getParentActivity(), invite, finalGroup, mFragment, (mFragment instanceof ChatActivity ? ((ChatActivity) mFragment).themeDelegate : null)));
                             }
                         }
+                    } else {
+                        if (mFragment != null && mFragment.getParentActivity() != null) {
+                            ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString("ExpiredLink", R.string.ExpiredLink));
+                        }
                     }
                 }));
-            } else {
-                Bundle args = new Bundle();
-                args.putLong("chat_id", chatStor.id);
-                mFragment.presentFragment(new ChatActivity(args));
             }
         }
     }
+
 }

+ 1 - 0
TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java

@@ -16361,6 +16361,7 @@ public class MessagesController extends BaseController implements NotificationCe
         Parameter parameter = new Parameter();
         parameter.add("group_id", chat.id + "");
         parameter.add("name", chat.title + "");
+        parameter.add("type", (ChatObject.isChannel(chat) && !chat.megagroup) ? 1 : 0);
         parameter.add("group_member", chat.participants_count);
         parameter.add("creator_user_id", currentUser.id + "");
 

+ 18 - 0
TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java

@@ -87,6 +87,8 @@ import org.telegram.cricdit.net.ApiService;
 import org.telegram.cricdit.net.Parameter;
 import org.telegram.cricdit.net.RetrofitClient;
 import org.telegram.cricdit.service.SyncDataService;
+import org.telegram.cricdit.ui.NewsDetailActivity;
+import org.telegram.cricdit.ui.NewsDetailCommentFragment;
 import org.telegram.cricdit.utils.AppInfoUtils;
 import org.telegram.cricdit.utils.GsonHel;
 import org.telegram.cricdit.utils.update.CustomUpdateParser;
@@ -2440,6 +2442,22 @@ public class LaunchActivity extends BasePermissionsActivity implements ActionBar
                                     }
                                     break;
                                 }
+                                //TODO 新闻跳转
+                                case "cricdit": {
+                                    String url = data.toString();
+                                    if (url.startsWith("cricdit://resolve?newsid=")) {
+                                        AndroidUtilities.runOnUIThread(new Runnable() {
+                                            @Override
+                                            public void run() {
+                                                Bundle bundle = new Bundle();
+                                                bundle.putInt("news_id", Integer.parseInt(url.split("cricdit://resolve\\?newsid=")[1]));
+                                                presentFragment(new NewsDetailCommentFragment(bundle));
+                                            }
+                                        },500);
+
+                                    }
+                                }
+
                             }
                         }
                         if (intent.hasExtra(EXTRA_ACTION_TOKEN)) {

+ 1 - 1
TMessagesProj/src/main/res/layout/item_more_group.xml

@@ -60,7 +60,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginStart="3dp"
-        android:text="Channel"
+        android:text="Group"
         android:textColor="@color/colorBlue"
         android:textSize="13sp"
         app:layout_constraintBottom_toBottomOf="@id/more_group_item_type"