diff --git a/app/build.gradle b/app/build.gradle index 6269e75..886f6da 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ buildscript { repositories { + + mavenCentral() maven { url 'https://maven.fabric.io/public' } } @@ -17,15 +19,15 @@ repositories { apply plugin: 'realm-android' android { - compileSdkVersion 26 - buildToolsVersion '26.0.2' + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { applicationId "net.iGap" minSdkVersion 15 - targetSdkVersion 25 - versionCode 64 - versionName "0.6.4" + targetSdkVersion 27 + versionCode 76 + versionName "0.9.2" multiDexEnabled true vectorDrawables.useSupportLibrary = true @@ -33,12 +35,18 @@ android { abiFilters "armeabi-v7a", "x86" } javaCompileOptions { + annotationProcessorOptions { includeCompileClasspath true } } } + compileOptions { + targetCompatibility 1.8 + sourceCompatibility 1.8 + } + dataBinding { enabled = true } @@ -51,6 +59,8 @@ android { } lintOptions { + checkReleaseBuilds false + abortOnError false disable 'MissingTranslation' } @@ -60,74 +70,83 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile project(':messageprogress') - compile project(':proto') - compile project(':websocket') - compile project(':libwebrtc') - compile('com.afollestad.material-dialogs:core:0.9.4.5') { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation project(':libwebrtc') + implementation('com.afollestad.material-dialogs:core:0.9.6.0') { transitive = true } - compile('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') { + implementation('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') { transitive = true } - - compile project(path: ':lvl') - compile(project(':compress')) { - exclude group: 'com.googlecode.mp4parser', module: 'isoparser' - } - compile(project(':k4l-video-trimmer')) { - exclude group: 'com.googlecode.mp4parser', module: 'isoparser' - } - + implementation project(path: ':lvl') implementation 'com.mikepenz:fastadapter:3.2.5' implementation 'com.mikepenz:fastadapter-commons:3.2.5' implementation 'com.mikepenz:fastadapter-extensions-expandable:3.2.5' implementation 'com.mikepenz:fastadapter-extensions:3.2.5' - - compile 'com.android.support:multidex:1.0.3' - compile 'com.android.support:appcompat-v7:26.0.2' - compile 'com.nineoldandroids:library:2.4.0' - compile 'com.android.support:recyclerview-v7:26.0.2' - compile 'com.android.support:design:26.0.2' - compile 'com.vicmikhailau:MaskedEditText:1.1.1' - compile 'com.uncopt:android.justified:1.0' - compile 'com.theartofdev.edmodo:android-image-cropper:2.7.0' - compile 'com.android.support:percent:26.0.2' - compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3@aar' - compile 'com.android.support:cardview-v7:26.0.2' - compile 'com.larswerkman:HoloColorPicker:1.5' - compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' - compile 'uk.co.chrisjenx:calligraphy:2.3.0' - compile 'me.leolin:ShortcutBadger:1.1.18@aar' - compile 'com.android.support:support-v4:26.0.2' - compile 'com.makeramen:roundedimageview:2.3.0' - compile 'dk.ilios:realmfieldnameshelper:1.1.1' - compile 'com.hanks.animatecheckbox:library:0.1' - compile 'org.parceler:parceler-api:1.1.9' - compile 'com.android.support:gridlayout-v7:26.0.2' - compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.3' - compile 'com.google.zxing:core:3.3.0' - compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.7' - compile 'com.google.android.gms:play-services-analytics:15.0.0' - compile 'com.google.android.gms:play-services-maps:15.0.0' - compile 'me.zhanghai.android.customtabshelper:library:1.0.3' - compile 'com.readystatesoftware.systembartint:systembartint:1.0.4' - compile 'cat.ereza:customactivityoncrash:2.1.0' - compile 'com.github.RooyeKhat-Media.Emoji:emoji-one:0.5.1.Fix6' - compile 'io.realm:android-adapters:3.0.0' - compile 'org.osmdroid:osmdroid-android:5.6.5' - compile 'io.fotoapparat.fotoapparat:library:1.3.0' - compile 'com.daimajia.swipelayout:library:1.2.0@aar' - compile 'com.github.pchmn:MaterialChipsInput:1.0.8' - testCompile 'junit:junit:4.12' + implementation 'com.android.support:multidex:1.0.3' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.nineoldandroids:library:2.4.0' + implementation 'com.android.support:recyclerview-v7:27.1.1' + implementation 'com.android.support:design:27.1.1' + implementation 'com.vicmikhailau:MaskedEditText:1.1.1' + implementation 'com.uncopt:android.justified:1.0' + implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' + implementation 'com.android.support:percent:27.1.1' + implementation 'com.timehop.stickyheadersrecyclerview:library:0.4.3@aar' + implementation 'com.android.support:cardview-v7:27.1.1' + implementation 'com.larswerkman:HoloColorPicker:1.5' + implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' + implementation 'uk.co.chrisjenx:calligraphy:2.3.0' + implementation 'me.leolin:ShortcutBadger:1.1.18@aar' + implementation 'com.android.support:support-v4:27.1.1' + implementation 'com.makeramen:roundedimageview:2.3.0' + implementation 'dk.ilios:realmfieldnameshelper:1.1.1' + implementation 'com.hanks.animatecheckbox:library:0.1' + implementation 'org.parceler:parceler-api:1.1.9' + implementation 'com.android.support:gridlayout-v7:27.1.1' + implementation 'com.google.zxing:core:3.3.0' + implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false } + implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.7' + implementation 'com.google.android.gms:play-services-analytics:16.0.0' + implementation 'com.google.android.gms:play-services-maps:15.0.1' + implementation 'me.zhanghai.android.customtabshelper:library:1.0.3' + implementation 'com.readystatesoftware.systembartint:systembartint:1.0.4' + implementation 'cat.ereza:customactivityoncrash:2.1.0' + implementation 'com.github.RooyeKhat-Media.Emoji:emoji-one:0.5.1.Fix2b' + implementation 'io.realm:android-adapters:3.0.0' + implementation 'org.osmdroid:osmdroid-android:5.6.5' + implementation 'io.fotoapparat.fotoapparat:library:1.3.0' + implementation 'com.daimajia.swipelayout:library:1.2.0@aar' + implementation 'com.github.pchmn:MaterialChipsInput:1.0.8' + testImplementation 'junit:junit:4.12' annotationProcessor 'org.parceler:parceler:1.1.6' - provided 'com.android.support:support-annotations:26.0.2' - compile group: 'com.github.msarhan', name: 'ummalqura-calendar', version: '1.1.7' - compile 'com.sothree.slidinguppanel:library:3.4.0' - compile 'com.github.krokyze:ucropnedit:2.2.2' + compileOnly 'com.android.support:support-annotations:27.1.1' + implementation group: 'com.github.msarhan', name: 'ummalqura-calendar', version: '1.1.7' + implementation 'com.sothree.slidinguppanel:library:3.4.0' + implementation 'com.github.krokyze:ucropnedit:2.2.2' implementation 'info.androidhive:imagefilters:1.0.7' - compile 'com.mindorks.android:prdownloader:0.3.0' + implementation 'com.mindorks.android:prdownloader:0.4.0' + implementation 'com.google.firebase:firebase-core:16.0.0' + implementation 'com.google.firebase:firebase-messaging:17.0.0' + implementation('com.github.RooyeKhat-Media:Compress:1.0.0') { + exclude group: 'com.googlecode.mp4parser', module: 'isoparser' + } + implementation('com.github.RooyeKhat-Media:VideoTrimmer:1.1.0') { + exclude group: 'com.googlecode.mp4parser', module: 'isoparser' + } + implementation 'com.github.RooyeKhat-Media:Websocket:1.0.0' + implementation 'com.github.RooyeKhat-Media:MessageProgress:1.0.0' + implementation 'com.github.RooyeKhat-Media:Proto:Build91' + implementation project(':pecpayment-release') + implementation project(':raadcore') + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.mcxiaoke.volley:library:1.0.19' + implementation 'com.squareup.picasso:picasso:2.5.2' + implementation 'com.squareup.retrofit2:retrofit:2.3.0' + implementation 'com.squareup.retrofit2:converter-gson:2.3.0' + implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0' + implementation project(':paygear_wallet') } configurations.all { @@ -135,8 +154,10 @@ configurations.all { def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { - details.useVersion '26.0.2' + details.useVersion '27.1.1' } } } } + +apply plugin: 'com.google.gms.google-services' diff --git a/app/google-services.json b/app/google-services.json index 4ce4888..ceb75a8 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -1,20 +1,31 @@ { "project_info": { - "project_number": "132364457498", - "project_id": "igap-messenger" + "project_number": "780057141561", + "firebase_url": "https://igap-im.firebaseio.com", + "project_id": "igap-im", + "storage_bucket": "igap-im.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:132364457498:android:69c59b7595e50096", + "mobilesdk_app_id": "1:780057141561:android:69c59b7595e50096", "android_client_info": { "package_name": "net.iGap" } }, - "oauth_client": [], + "oauth_client": [ + { + "client_id": "780057141561-etdtrh2c8au993nmrigoj0jfjoplu3t8.apps.googleusercontent.com", + "client_type": 3 + }, + { + "client_id": "780057141561-etdtrh2c8au993nmrigoj0jfjoplu3t8.apps.googleusercontent.com", + "client_type": 3 + } + ], "api_key": [ { - "current_key": "AIzaSyCCC20H7heNcUEgRD3nsdOOq1hojHI-tSs" + "current_key": "AIzaSyDJlUADMuvqi9xv4KiGkPqY69ULf8FMmxA" } ], "services": { @@ -29,7 +40,7 @@ "other_platform_oauth_client": [] }, "ads_service": { - "status": 1 + "status": 2 } } } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 9e553f9..afc1769 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -206,3 +206,29 @@ -dontwarn com.yalantis.ucrop** -keep class com.yalantis.ucrop** { *; } -keep interface com.yalantis.ucrop** { *; } + +### Wallet + +-keepclassmembers class * { + native ; +} + +-dontwarn okhttp3.** +-dontwarn com.android.volley.toolbox.** + +-keepattributes Annotation,SourceFile,LineNumberTable + +-dontwarn okio.** +-dontwarn javax.annotation.** +-dontwarn com.squareup.okhttp.** +-dontnote retrofit2.Platform +-dontnote retrofit2.Platform$IOS$MainThreadExecutor +-dontwarn retrofit2.Platform$Java8 +### -keepattributes Signature // used this line before +-keepattributes Exceptions +-keepattributes EnclosingMethod + +-keep class org.paygear.** { *; } +-keep class ir.radsense.** { *; } + +-dontwarn com.alexvasilkov.gestures** \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e5c35b4..ef17d16 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,6 +9,9 @@ + + + @@ -38,6 +41,8 @@ + + + tools:replace="allowBackup,supportsRtl"> @@ -99,6 +105,16 @@ android:excludeFromRecents="true" android:launchMode="singleInstance"> + + + + + + @@ -222,7 +259,8 @@ + android:exported="true" + android:process=":auth"> @@ -231,6 +269,18 @@ android:resource="@xml/authenticator" /> + + + + + + + + + + + + + android:value="Your_Fabric_Key" /> + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/net/iGap/Config.java b/app/src/main/java/net/iGap/Config.java index de7d6ae..3cbdf65 100644 --- a/app/src/main/java/net/iGap/Config.java +++ b/app/src/main/java/net/iGap/Config.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap; @@ -16,7 +16,7 @@ public class Config { public static final int ACCEPT = 1; public static final int REJECT = 0; - public static final int REALM_SCHEMA_VERSION = 18; + public static final int REALM_SCHEMA_VERSION = 20; public static final int REALM_LATEST_MIGRATION_VERSION = REALM_SCHEMA_VERSION - 1; public static final int LOOKUP_MAP_RESPONSE_OFFSET = 30000; public static final int MAX_TEXT_ATTACHMENT_LENGTH = 200; @@ -53,6 +53,7 @@ public class Config { public static final int FETCH_CONTACT_TIME_OUT = (int) (5 * DateUtils.SECOND_IN_MILLIS); public static final int LAST_SEEN_TIME_OUT = (int) (60 * DateUtils.MINUTE_IN_MILLIS); // after this time show exactly time instead of minutes public static final int DEFAULT_BOTH_CHAT_DELETE_TIME = (int) (2 * DateUtils.HOUR_IN_MILLIS); + public static final String iGapAccount = "iGap"; public static final String URL_WEBSOCKET = "wss://secure.igap.net/hybrid/"; public static final String URL_MAP = "https://c.tile.openstreetmap.org/"; public static final String IGAP_LINK_PREFIX = "https://iGap.net/"; @@ -71,40 +72,6 @@ public class Config { public static final String BASE64_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsm4sNLgDVqPf0ZxLWH3vkB1mPzHIkGWIJtNelibcTtzhipRv0iHeS3Z0wzeQpwYcMbkWQ81+WtgJwxUujitPOZnHvBex8qQLJ2JH33DvevWOgLDWPKEnKlfdi3Qg09pfO/Bx7eoWznWhRR6ZNjRgzY+P/2AaW77/f3wq3XHbHldM3jUrqwValwrWrkigIR0MFTkaGkg11T9JCFvO/L/FaZCAybuutje+H1nmNav3r8Xv6eBYS0nSVEm0dm5h46ECQi9PIxOCSMJ1McZMRkb8UaCScCAxh6lkD9fgZrOT5XQa8EOSWOwHx" + "+uQWdR0efHyYbdC3A8zoJZjxBVtvVnDYwIDAQAB"; - public static String default_appBarColor = "#00B0BF"; - public static String default_notificationColor = "#e51c23"; - public static String default_toggleButtonColor = "#00B0BF"; - public static String default_attachmentColor = "#00B0BF"; - public static String default_headerTextColor = "#00B0BF"; - public static String default_progressColor = "#00B0BF"; - public static String default_dark_appBarColor = "#000000"; - public static String default_dark_notificationColor = "#000000"; - public static String default_dark_toggleButtonColor = "#000000"; - public static String default_dark_attachmentColor = "#000000"; - public static String default_dark_menuBackgroundColor = "#000000"; - public static String default_dark_headerTextColor = "#ffffff"; - public static String default_dark_progressColor = "#ffffff"; - - public static void darkThemeColor() { - G.backgroundTheme = "#151515"; - G.textTitleTheme = "#ffffff"; - G.textSubTheme = "#ffffff"; - G.tintImage = "#ffffff"; - G.backgroundTheme_2 = "#000000"; - G.logLineTheme = "#4b4b4b"; - G.voteIconTheme = "#cacaca"; - } - - public static void lightThemeColor() { - G.backgroundTheme = "#FFFFFF"; - G.textTitleTheme = "#000000"; - G.textSubTheme = "#bbbbbb"; - G.tintImage = "#000000"; - G.backgroundTheme_2 = "#f9f9f9"; - G.logLineTheme = "#e9e9e9"; - G.voteIconTheme = "#696969"; - - } } diff --git a/app/src/main/java/net/iGap/G.java b/app/src/main/java/net/iGap/G.java index 288c9bc..7fb1714 100644 --- a/app/src/main/java/net/iGap/G.java +++ b/app/src/main/java/net/iGap/G.java @@ -1,15 +1,16 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap; +import android.accounts.Account; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; @@ -43,6 +44,9 @@ import net.iGap.proto.ProtoClientCondition; import net.iGap.request.RequestWrapper; +import org.paygear.wallet.model.Card; +import org.paygear.wallet.utils.Utils; + import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -55,6 +59,8 @@ import cat.ereza.customactivityoncrash.config.CaocConfig; import io.fabric.sdk.android.Fabric; +import ir.radsense.raadcore.Raad; +import ir.radsense.raadcore.web.WebBase; import static net.iGap.Config.DEFAULT_BOTH_CHAT_DELETE_TIME; @@ -109,9 +115,15 @@ public class G extends MultiDexApplication { public static String selectedLanguage = "en"; public static String symmetricMethod; public static String appBarColor; // default color + public static String bubbleChatSend; // default color + public static String bubbleChatReceive; // default color + public static String fabBottom; // default color + public static String bubbleChatMusic; // default color + public static String textChatMusic; public static String notificationColor; public static String toggleButtonColor; public static String attachmentColor; + public static String iconColorBottomSheet; public static String progressColor; public static String headerTextColor; public static String backgroundTheme; @@ -119,8 +131,13 @@ public class G extends MultiDexApplication { public static String logLineTheme; public static String voteIconTheme; public static String textTitleTheme; + public static String textBubble; + public static String linkColor; + public static String txtIconCheck; + public static String textBubbleSend; public static String textSubTheme; public static String tintImage; + public static String lineBorder; public static String menuBackgroundColor; public static String authorHash; public static String displayName; @@ -154,7 +171,11 @@ public class G extends MultiDexApplication { public static boolean isLandscape = false; public static boolean isAppRtl = false; public static boolean isLinkClicked = false; + public static boolean isMplActive = false; + public static boolean isWalletActive = false; + public static boolean isWalletRegister = false; public static boolean isDarkTheme = false; + public static int themeColor; public static String selectedTabInMainActivity = ""; public static int ivSize; public static int userTextSize = 0; @@ -180,6 +201,7 @@ public class G extends MultiDexApplication { public static OnClientSearchRoomHistory onClientSearchRoomHistory; public static OnUserVerification onUserVerification; public static OnReceivePageInfoTOS onReceivePageInfoTOS; + public static OnReceivePageInfoWalletAgreement onReceivePageInfoWalletAgreement; public static OnUserLogin onUserLogin; public static OnUserProfileSetEmailResponse onUserProfileSetEmailResponse; public static OnUserProfileSetGenderResponse onUserProfileSetGenderResponse; @@ -190,6 +212,7 @@ public class G extends MultiDexApplication { public static OnUserContactDelete onUserContactdelete; public static OnClientGetRoomListResponse onClientGetRoomListResponse; public static OnClientGetRoomResponse onClientGetRoomResponse; + public static OnInquiry onInquiry; public static OnSecuring onSecuring; public static OnChatGetRoom onChatGetRoom; public static OnChatEditMessageResponse onChatEditMessageResponse; @@ -331,6 +354,8 @@ public class G extends MultiDexApplication { public static OnGeoCommentResponse onGeoCommentResponse; public static OnGeoGetConfiguration onGeoGetConfiguration; public static OnNotifyTime onNotifyTime; + public static OnPayment onPayment; + public static OnMplResult onMplResult; public static ISignalingOffer iSignalingOffer; public static ISignalingRinging iSignalingRinging; public static ISignalingAccept iSignalingAccept; @@ -354,12 +379,19 @@ public class G extends MultiDexApplication { public static boolean isTimeWhole = false; public static FragmentManager fragmentManager; private Tracker mTracker; + public static Account iGapAccount; + public static Card selectedCard = null; + public static long cardamount; + public static String jwt = null; + + public static int rotationState; @Override public void onCreate() { super.onCreate(); + G.firstTimeEnterToApp = true; new Thread(new Runnable() { @@ -374,6 +406,10 @@ public void run() { handler = new Handler(); inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); + Raad.init(getApplicationContext()); + Utils.setInstart(context, "fa"); + WebBase.apiKey = "5aa7e856ae7fbc00016ac5a01c65909797d94a16a279f46a4abb5faa"; + new StartupActions(); } @@ -421,7 +457,7 @@ public void onConfigurationChanged(Configuration newConfig) { synchronized public Tracker getDefaultTracker() { if (mTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); - mTracker = analytics.newTracker(R.xml.global_tracker); + mTracker = analytics.newTracker(R.xml.global_track); } return mTracker; } diff --git a/app/src/main/java/net/iGap/Theme.java b/app/src/main/java/net/iGap/Theme.java new file mode 100644 index 0000000..725bae8 --- /dev/null +++ b/app/src/main/java/net/iGap/Theme.java @@ -0,0 +1,861 @@ +package net.iGap; + +import android.app.Application; +import android.content.SharedPreferences; +import android.graphics.Color; + +import com.vanniktech.emoji.EmojiManager; +import com.vanniktech.emoji.EmojiPopup; +import com.vanniktech.emoji.one.EmojiOneProvider; + +import net.iGap.module.SHP_SETTING; + +import static net.iGap.G.appBarColor; +import static net.iGap.G.attachmentColor; +import static net.iGap.G.context; +import static net.iGap.G.headerTextColor; +import static net.iGap.G.notificationColor; +import static net.iGap.G.toggleButtonColor; + +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ +public class Theme extends Application { + + public static final int CUSTOM = 0; + public static final int DEFAULT = 1; + public static final int DARK = 2; + public static final int RED = 3; + public static final int PINK = 4; + public static final int PURPLE = 5; + public static final int DEEPPURPLE = 6; + public static final int INDIGO = 7; + public static final int BLUE = 8; + public static final int LIGHT_BLUE = 9; + public static final int CYAN = 10; + public static final int TEAL = 11; + public static final int GREEN = 12; + public static final int LIGHT_GREEN = 13; + public static final int LIME = 14; + public static final int YELLLOW = 15; + public static final int AMBER = 16; + public static final int ORANGE = 17; + public static final int DEEP_ORANGE = 18; + public static final int BROWN = 19; + public static final int GREY = 20; + public static final int BLUE_GREY = 21; + public static final int BLUE_GREY_COMPLETE = 22; + public static final int INDIGO_COMPLETE = 23; + public static final int BROWN_COMPLETE = 24; + public static final int TEAL_COMPLETE = 25; + public static final int GREY_COMPLETE = 26; + + + public static String default_appBarColor = "#00B0BF"; + public static String default_notificationColor = "#e51c23"; + public static String default_toggleButtonColor = "#00B0BF"; + public static String default_attachmentColor = "#00B0BF"; + public static String default_headerTextColor = "#00B0BF"; + public static String default_progressColor = "#00B0BF"; + + public static String default_dark_appBarColor = "#000000"; + public static String default_dark_notificationColor = "#000000"; + public static String default_dark_toggleButtonColor = "#000000"; + public static String default_dark_attachmentColor = "#ffffff"; + public static String default_dark_menuBackgroundColor = "#000000"; + public static String default_dark_headerTextColor = "#ffffff"; + public static String default_dark_progressColor = "#ffffff"; + + public static String default_red_appBarColor = "#F44336"; + public static String default_Pink_appBarColor = "#E91E63"; + public static String default_purple_appBarColor = "#9C27B0"; + public static String default_deepPurple_appBarColor = "#673AB7"; + public static String default_indigo_appBarColor = "#3F51B5"; + public static String default_blue_appBarColor = "#2196F3"; + public static String default_lightBlue_appBarColor = "#03A9F4"; + public static String default_cyan_appBarColor = "#00BCD4"; + public static String default_teal_appBarColor = "#009688"; + public static String default_green_appBarColor = "#388E3C"; + public static String default_lightGreen_appBarColor = "#689F38"; + public static String default_lime_appBarColor = "#AFB42B"; + public static String default_yellow_appBarColor = "#FBC02D"; + public static String default_amber_appBarColor = "#FFA000"; + public static String default_orange_appBarColor = "#F57C00"; + public static String default_deepOrange_appBarColor = "#E64A19"; + public static String default_brown_appBarColor = "#5D4037"; + public static String default_grey_appBarColor = "#616161"; + public static String default_blueGrey_appBarColor = "#455A64"; + public static String lineView = "#52afafaf"; + + + public static void setThemeColor() { + + SharedPreferences preferences = context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); + G.themeColor = preferences.getInt(SHP_SETTING.KEY_THEME_COLOR, DEFAULT); + G.isDarkTheme = preferences.getBoolean(SHP_SETTING.KEY_THEME_DARK, false); + + /*if (G.themeColor == DARK) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + }*/ + EmojiManager.install(new EmojiOneProvider()); + + + switch (G.themeColor) { + case CUSTOM: + setColor(false, + preferences.getString(SHP_SETTING.KEY_APP_BAR_COLOR, default_appBarColor), + preferences.getString(SHP_SETTING.KEY_NOTIFICATION_COLOR, default_notificationColor), + preferences.getString(SHP_SETTING.KEY_TOGGLE_BOTTON_COLOR, default_toggleButtonColor), + preferences.getString(SHP_SETTING.KEY_SEND_AND_ATTACH_ICON_COLOR, default_attachmentColor), + preferences.getString(SHP_SETTING.KEY_FONT_HEADER_COLOR, default_headerTextColor), + preferences.getString(SHP_SETTING.KEY_PROGRES_COLOR, default_progressColor), + lineView, + "#FFFFFF", + "#f9f9f9", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#e679dde6", + "#FFFFFF", + preferences.getString(SHP_SETTING.KEY_APP_BAR_COLOR, default_appBarColor), + "#000000", + "#2A2A2A", + "#bfefef", + "#303F9F", + "#212121" + + ); + + break; + case DEFAULT: + setColor(false, + default_appBarColor, + default_notificationColor, + default_toggleButtonColor, + default_attachmentColor, + default_headerTextColor, + default_progressColor, + lineView, + "#FFFFFF", + "#f9f9f9", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#e679dde6", + "#FFFFFF", + "#00BCD4", + "#000000", + "#2A2A2A", + "#bfefef", + "#303F9F", + "#212121" + ); + + break; + case DARK: + setColor(true, + default_dark_appBarColor, + default_dark_notificationColor, + default_dark_toggleButtonColor, + default_dark_attachmentColor, + default_dark_headerTextColor, + default_dark_progressColor, + "#313131", + "#151515", + "#000000", + "#ffffff", + "#ffffff", + "#ffffff", + "#4b4b4b", + "#cacaca", + "#151515", + "#c7101010", + "#2A2A2A", + "#ffffff", + "#ffffff", + "#313131", + "#00BCD4", + "#ffffff" + ); + + break; + case RED: + setColor(false, + default_red_appBarColor, + default_red_appBarColor, + default_red_appBarColor, + default_red_appBarColor, + default_red_appBarColor, + default_red_appBarColor, + "#ffcdd2",// is set + "#FFFFFF", + "#ef9a9a", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#D32F2F", + "#FF5252", + "#FF5252", + "#FFFFFF", + "#FFFFFF", + "#ffcdd2", + "#283593", + "#212121" + ); + break; + case PINK: + setColor(false, + default_Pink_appBarColor, + default_Pink_appBarColor, + default_Pink_appBarColor, + default_Pink_appBarColor, + default_Pink_appBarColor, + default_Pink_appBarColor, + "#f8bbd0",// is set + "#FFFFFF", + "#f48fb1", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#C2185B", + "#FF4081", + "#FF4081", + "#FFFFFF", + "#FFFFFF", + "#f8bbd0", + "#283593", + "#212121" + ); + break; + case PURPLE: + setColor(false, + default_purple_appBarColor, + default_purple_appBarColor, + default_purple_appBarColor, + default_purple_appBarColor, + default_purple_appBarColor, + default_purple_appBarColor, + "#e1bee7",// is set + "#FFFFFF", + "#ce93d8", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#7B1FA2", + "#E040FB", + "#E040FB", + "#FFFFFF", + "#FFFFFF", + "#e1bee7", + "#303F9F", + "#212121" + ); + break; + case DEEPPURPLE: + setColor(false, + default_deepPurple_appBarColor, + default_deepPurple_appBarColor, + default_deepPurple_appBarColor, + default_deepPurple_appBarColor, + default_deepPurple_appBarColor, + default_deepPurple_appBarColor, + "#d1c4e9",// is set + "#FFFFFF", + "#b39ddb", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#512DA8", + "#7C4DFF", + "#7C4DFF", + "#FFFFFF", + "#FFFFFF", + "#d1c4e9", + "#303F9F", + "#212121" + ); + break; + case INDIGO: + setColor(false, + default_indigo_appBarColor, + default_indigo_appBarColor, + default_indigo_appBarColor, + default_indigo_appBarColor, + default_indigo_appBarColor, + default_indigo_appBarColor, + "#c5cae9",// line + "#FFFFFF", + "#9fa8da", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#303F9F", + "#536DFE", + "#536DFE",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#c5cae9", + "#00BCD4", + "#212121" + ); + break; + case BLUE: + setColor(false, + default_blue_appBarColor, + default_blue_appBarColor, + default_blue_appBarColor, + default_blue_appBarColor, + default_blue_appBarColor, + default_blue_appBarColor, + "#bbdefb",// line + "#FFFFFF", + "#90caf9", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#1976D2", + "#448AFF", + "#03A9F4",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#bbdefb", + "#283593", + "#212121" + ); + break; + + case LIGHT_BLUE: + setColor(false, + default_lightBlue_appBarColor, + default_lightBlue_appBarColor, + default_lightBlue_appBarColor, + default_lightBlue_appBarColor, + default_lightBlue_appBarColor, + default_lightBlue_appBarColor, + "#b3e5fc",// line + "#FFFFFF", + "#81d4fa", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#0288D1", + "#03A9F4", + "#03A9F4",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#b3e5fc", + "#283593", + "#212121" + ); + break; + + case CYAN: + setColor(false, + default_cyan_appBarColor, + default_cyan_appBarColor, + default_cyan_appBarColor, + default_cyan_appBarColor, + default_cyan_appBarColor, + default_cyan_appBarColor, + "#b2ebf2",// line + "#FFFFFF", + "#81d4fa", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#0097A7", + "#00BCD4", + "#00BCD4",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#b2ebf2", + "#283593", + "#212121" + ); + break; + case TEAL: + setColor(false, + default_teal_appBarColor, + default_teal_appBarColor, + default_teal_appBarColor, + default_teal_appBarColor, + default_teal_appBarColor, + default_teal_appBarColor, + "#b2dfdb",// line + "#FFFFFF", + "#80cbc4", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#00796B", + "#009688", + "#009688",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#b2dfdb", + "#303F9F", + "#212121" + ); + break; + case GREEN: + setColor(false, + default_green_appBarColor, + default_green_appBarColor, + default_green_appBarColor, + default_green_appBarColor, + default_green_appBarColor, + default_green_appBarColor, + "#c8e6c9",// line + "#FFFFFF", + "#a5d6a7", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#388E3C", + "#4CAF50", + "#4CAF50",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#c8e6c9", + "#283593", + "#212121" + ); + break; + case LIGHT_GREEN: + setColor(false, + default_lightGreen_appBarColor, + default_lightGreen_appBarColor, + default_lightGreen_appBarColor, + default_lightGreen_appBarColor, + default_lightGreen_appBarColor, + default_lightGreen_appBarColor, + "#dcedc8",// line + "#FFFFFF", + "#c5e1a5", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#689F38", + "#8BC34A", + "#8BC34A",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#dcedc8", + "#283593", + "#212121" + ); + break; + case LIME: + setColor(false, + default_lime_appBarColor, + default_lime_appBarColor, + default_lime_appBarColor, + default_lime_appBarColor, + default_lime_appBarColor, + default_lime_appBarColor, + "#f0f4c3",// line + "#FFFFFF", + "#e6ee9c", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#AFB42B", + "#CDDC39", + "#CDDC39",//fab bottom + "#212121", + "#212121", + "#f0f4c3", + "#283593", + "#212121" + ); + break; + + case YELLLOW: + setColor(false, + default_yellow_appBarColor, + default_yellow_appBarColor, + default_yellow_appBarColor, + default_yellow_appBarColor, + default_yellow_appBarColor, + default_yellow_appBarColor, + "#fff9c4",// line + "#FFFFFF", + "#fff59d", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#FBC02D", + "#FFEB3B", + "#FFEB3B",//fab bottom + "#212121", + "#212121", + "#fff9c4", + "#00BCD4", + "#212121" + ); + break; + case AMBER: + setColor(false, + default_amber_appBarColor, + default_amber_appBarColor, + default_amber_appBarColor, + default_amber_appBarColor, + default_amber_appBarColor, + default_amber_appBarColor, + "#ffecb3",// line + "#FFFFFF", + "#ffe082", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#FFA000", + "#FFC107", + "#FFC107",//fab bottom + "#212121", + "#212121", + "#ffecb3", + "#283593", + "#212121" + ); + break; + case ORANGE: + setColor(false, + default_orange_appBarColor, + default_orange_appBarColor, + default_orange_appBarColor, + default_orange_appBarColor, + default_orange_appBarColor, + default_orange_appBarColor, + "#ffe0b2",// line + "#FFFFFF", + "#ffcc80", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#F57C00", + "#FF9800", + "#FF9800",//fab bottom + "#212121", + "#212121", + "#ffe0b2", + "#283593", + "#212121" + ); + break; + + case DEEP_ORANGE: + setColor(false, + default_deepOrange_appBarColor, + default_deepOrange_appBarColor, + default_deepOrange_appBarColor, + default_deepOrange_appBarColor, + default_deepOrange_appBarColor, + default_deepOrange_appBarColor, + "#ffccbc",// line + "#FFFFFF", + "#ffab91", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#E64A19", + "#FF5722", + "#FF5722",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#ffccbc", + "#536DFE", + "#212121" + + ); + break; + + case BROWN: + setColor(false, + default_brown_appBarColor, + default_brown_appBarColor, + default_brown_appBarColor, + default_brown_appBarColor, + default_brown_appBarColor, + default_brown_appBarColor, + "#d7ccc8",// line + "#FFFFFF", + "#bcaaa4", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#5D4037", + "#795548", + "#795548",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#d7ccc8", + "#303F9F", + "#212121" + ); + break; + case GREY: + setColor(false, + default_grey_appBarColor, + default_grey_appBarColor, + default_grey_appBarColor, + default_grey_appBarColor, + default_grey_appBarColor, + default_grey_appBarColor, + "#f5f5f5",// line + "#FFFFFF", + "#e0e0e0", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#616161", + "#9E9E9E", + "#9E9E9E",//fab bottom + "#ffffff", + "#212121", + "#f5f5f5", + "#536DFE", + "#212121" + + ); + break; + case BLUE_GREY: + setColor(false, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + "#cfd8dc",// line + "#FFFFFF", + "#b0bec5", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#455A64", + "#607D8B", + "#607D8B",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#cfd8dc", + "#303F9F", + "#212121" + ); + break; + case BLUE_GREY_COMPLETE: + setColor(false, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + default_blueGrey_appBarColor, + "#607D8B",// line + "#CFD8DC", + "#b0bec5", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#455A64", + "#607D8B", + "#607D8B",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#cfd8dc", + "#00bcd4", + "#212121" + ); + break; + + case INDIGO_COMPLETE: + setColor(false, + default_indigo_appBarColor, + default_indigo_appBarColor, + default_indigo_appBarColor, + default_indigo_appBarColor, + default_indigo_appBarColor, + default_indigo_appBarColor, + "#3f51b5",// line + "#C5CAE9", + "#9fa8da", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#303F9F", + "#3f51b5", + "#3f51b5",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#C5CAE9", + "#448AFF", + "#212121" + + ); + break; + case BROWN_COMPLETE: + setColor(false, + default_brown_appBarColor, + default_brown_appBarColor, + default_brown_appBarColor, + default_brown_appBarColor, + default_brown_appBarColor, + default_brown_appBarColor, + "#795548",// line + "#D7CCC8", + "#bcaaa4", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#5D4037", + "#795548", + "#795548",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#D7CCC8", + "#00bcd4", + "#212121" + ); + break; + case TEAL_COMPLETE: + setColor(false, + default_teal_appBarColor, + default_teal_appBarColor, + default_teal_appBarColor, + default_teal_appBarColor, + default_teal_appBarColor, + default_teal_appBarColor, + "#009688",// line + "#B2DFDB", + "#80cbc4", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#00796B", + "#009688", + "#009688",//fab bottom + "#FFFFFF", + "#FFFFFF", + "#B2DFDB", + "#303F9F", + "#212121" + ); + break; + + case GREY_COMPLETE: + setColor(false, + default_grey_appBarColor, + default_grey_appBarColor, + default_grey_appBarColor, + default_grey_appBarColor, + default_grey_appBarColor, + default_grey_appBarColor, + "#e0e0e0",// line + "#F5F5F5", + "#e0e0e0", + "#000000", + "#bbbbbb", + "#000000", + "#e9e9e9", + "#FFFFFF", + "#616161", + "#9E9E9E", + "#9E9E9E",//fab bottom + "#ffffff", + "#212121", + "#F5F5F5", + "#2196f3", + "#212121" + ); + break; + } + } + + private static void setColor(boolean isDarkTheme, String... color) { + + G.isDarkTheme = isDarkTheme; + + appBarColor = color[0]; + notificationColor = color[1]; + toggleButtonColor = color[2]; + attachmentColor = color[3]; + headerTextColor = color[4]; + G.progressColor = color[5]; + + G.lineBorder = color[6];// ok + G.backgroundTheme = color[7]; + G.backgroundTheme_2 = color[8]; + G.textTitleTheme = color[9]; + G.textSubTheme = color[10]; + G.tintImage = color[11]; + G.logLineTheme = color[12]; + G.voteIconTheme = color[13]; + G.bubbleChatSend = color[14]; + G.bubbleChatReceive = color[15]; + G.fabBottom = color[16]; + G.textBubble = color[17]; + G.txtIconCheck = color[18]; + G.bubbleChatMusic = color[19]; + G.linkColor = color[20]; + G.textChatMusic = color[21]; + + } + +} diff --git a/app/src/main/java/net/iGap/activities/ActivityCall.java b/app/src/main/java/net/iGap/activities/ActivityCall.java index f36d9cb..7cf5e45 100644 --- a/app/src/main/java/net/iGap/activities/ActivityCall.java +++ b/app/src/main/java/net/iGap/activities/ActivityCall.java @@ -14,7 +14,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.SharedPreferences; import android.databinding.DataBindingUtil; import android.hardware.Sensor; import android.hardware.SensorEvent; @@ -40,14 +39,11 @@ import net.iGap.interfaces.OnCallLeaveView; import net.iGap.interfaces.OnGetPermission; import net.iGap.module.MaterialDesignTextView; -import net.iGap.module.SHP_SETTING; import net.iGap.viewmodel.ActivityCallViewModel; import net.iGap.webrtc.WebRTC; import java.io.IOException; -import static net.iGap.G.context; - public class ActivityCall extends ActivityEnhanced implements OnCallLeaveView { public static final String USER_ID_STR = "USER_ID"; @@ -125,14 +121,6 @@ public void onBackPressed() throws IllegalStateException { public void onCreate(Bundle savedInstanceState) { // requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN | LayoutParams.FLAG_KEEP_SCREEN_ON | LayoutParams.FLAG_DISMISS_KEYGUARD | LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_TURN_SCREEN_ON); - - SharedPreferences preferences = context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - if (preferences.getBoolean(SHP_SETTING.KEY_THEME_DARK, false)) { - this.setTheme(R.style.Material_blackCustom); - } else { - this.setTheme(R.style.Material_lightCustom); - } - super.onCreate(savedInstanceState); if (isGoingfromApp) { diff --git a/app/src/main/java/net/iGap/activities/ActivityCustomError.java b/app/src/main/java/net/iGap/activities/ActivityCustomError.java index 4ab6d2d..626aab0 100644 --- a/app/src/main/java/net/iGap/activities/ActivityCustomError.java +++ b/app/src/main/java/net/iGap/activities/ActivityCustomError.java @@ -1,7 +1,6 @@ package net.iGap.activities; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.Color; import android.os.Bundle; import android.view.View; @@ -9,23 +8,14 @@ import net.iGap.G; import net.iGap.R; -import net.iGap.module.SHP_SETTING; import cat.ereza.customactivityoncrash.CustomActivityOnCrash; import cat.ereza.customactivityoncrash.config.CaocConfig; -import static net.iGap.G.context; - public class ActivityCustomError extends ActivityEnhanced { @Override public void onCreate(Bundle savedInstanceState) { - SharedPreferences preferences = context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - if (G.isDarkTheme) { - this.setTheme(R.style.Material_blackCustom); - } else { - this.setTheme(R.style.Material_lightCustom); - } super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_error); diff --git a/app/src/main/java/net/iGap/activities/ActivityEnhanced.java b/app/src/main/java/net/iGap/activities/ActivityEnhanced.java index 5904829..a61814e 100644 --- a/app/src/main/java/net/iGap/activities/ActivityEnhanced.java +++ b/app/src/main/java/net/iGap/activities/ActivityEnhanced.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.activities; @@ -30,6 +30,8 @@ import net.iGap.Config; import net.iGap.G; +import net.iGap.R; +import net.iGap.Theme; import net.iGap.WebSocketClient; import net.iGap.helper.HelperLog; import net.iGap.helper.HelperPermission; @@ -84,6 +86,9 @@ protected void onResume() { public void onCreate(Bundle savedInstanceState) { + setThemeSetting(); + + checkFont(); IntentFilter screenStateFilter = new IntentFilter(); @@ -127,6 +132,103 @@ public void onCreate(Bundle savedInstanceState) { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); } + private void setThemeSetting() { + switch (G.themeColor) { + case Theme.CUSTOM: + this.setTheme(R.style.Material_lightCustom); + break; + case Theme.DEFAULT: + this.setTheme(R.style.Material_lightCustom); + break; + case Theme.DARK: + this.setTheme(R.style.Material_blackCustom); + break; + case Theme.RED: + this.setTheme(R.style.Material_red); + break; + case Theme.PINK: + this.setTheme(R.style.Material_pink); + break; + case Theme.PURPLE: + this.setTheme(R.style.Material_purple); + break; + case Theme.DEEPPURPLE: + this.setTheme(R.style.Material_deepPurple); + break; + case Theme.INDIGO: + this.setTheme(R.style.Material_indigo); + break; + case Theme.BLUE: + this.setTheme(R.style.Material_blue); + break; + + case Theme.LIGHT_BLUE: + this.setTheme(R.style.Material_lightBlue); + break; + + case Theme.CYAN: + this.setTheme(R.style.Material_cyan); + break; + + case Theme.TEAL: + this.setTheme(R.style.Material_teal); + break; + + case Theme.GREEN: + this.setTheme(R.style.Material_green); + break; + + case Theme.LIGHT_GREEN: + this.setTheme(R.style.Material_lightGreen); + break; + + case Theme.LIME: + this.setTheme(R.style.Material_lime); + break; + + case Theme.YELLLOW: + this.setTheme(R.style.Material_yellow); + break; + case Theme.AMBER: + this.setTheme(R.style.Material_amber); + break; + + case Theme.ORANGE: + this.setTheme(R.style.Material_orange); + break; + + case Theme.DEEP_ORANGE: + this.setTheme(R.style.Material_deepOrange); + break; + case Theme.BROWN: + this.setTheme(R.style.Material_brown); + break; + case Theme.GREY: + this.setTheme(R.style.Material_grey); + break; + case Theme.BLUE_GREY: + this.setTheme(R.style.Material_blueGrey); + break; + case Theme.BLUE_GREY_COMPLETE: + this.setTheme(R.style.Material_blueGreyComplete); + break; + case Theme.INDIGO_COMPLETE: + this.setTheme(R.style.Material_indigoComplete); + break; + case Theme.BROWN_COMPLETE: + this.setTheme(R.style.Material_BrownComplete); + break; + case Theme.TEAL_COMPLETE: + this.setTheme(R.style.Material_TealComplete); + break; + case Theme.GREY_COMPLETE: + this.setTheme(R.style.Material_GreyComplete); + break; + + } + + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); diff --git a/app/src/main/java/net/iGap/activities/ActivityEnterPassCode.java b/app/src/main/java/net/iGap/activities/ActivityEnterPassCode.java index 532a4f7..31fadfd 100644 --- a/app/src/main/java/net/iGap/activities/ActivityEnterPassCode.java +++ b/app/src/main/java/net/iGap/activities/ActivityEnterPassCode.java @@ -9,19 +9,14 @@ * All rights reserved. */ -import android.content.SharedPreferences; import android.databinding.DataBindingUtil; import android.os.Build; import android.os.Bundle; -import net.iGap.G; import net.iGap.R; import net.iGap.databinding.ActivityEnterPassCodeBinding; -import net.iGap.module.SHP_SETTING; import net.iGap.viewmodel.ActivityEnterPassCodeViewModel; -import static net.iGap.G.context; - public class ActivityEnterPassCode extends ActivityEnhanced { private ActivityEnterPassCodeViewModel activityManageSpaceViewModel; @@ -29,13 +24,6 @@ public class ActivityEnterPassCode extends ActivityEnhanced { @Override public void onCreate(Bundle savedInstanceState) { - SharedPreferences preferences = context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - if (G.isDarkTheme) { - this.setTheme(R.style.Material_blackCustom); - } else { - this.setTheme(R.style.Material_lightCustom); - } - super.onCreate(savedInstanceState); ActivityEnterPassCodeBinding activityEnterPassCodeBinding = DataBindingUtil.setContentView(this, R.layout.activity_enter_pass_code); activityManageSpaceViewModel = new ActivityEnterPassCodeViewModel(this, activityEnterPassCodeBinding.getRoot()); diff --git a/app/src/main/java/net/iGap/activities/ActivityMain.java b/app/src/main/java/net/iGap/activities/ActivityMain.java index 20e925b..c2cca73 100644 --- a/app/src/main/java/net/iGap/activities/ActivityMain.java +++ b/app/src/main/java/net/iGap/activities/ActivityMain.java @@ -1,32 +1,28 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.activities; -import android.Manifest; -import android.accounts.Account; -import android.accounts.AccountManager; import android.content.Intent; import android.content.SharedPreferences; -import android.content.pm.PackageManager; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.graphics.Color; import android.graphics.Typeface; import android.media.AudioManager; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.AppBarLayout; import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; @@ -52,20 +48,29 @@ import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.GravityEnum; import com.afollestad.materialdialogs.MaterialDialog; +import com.crashlytics.android.Crashlytics; import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.Tracker; +import com.google.zxing.integration.android.IntentIntegrator; +import com.google.zxing.integration.android.IntentResult; import net.iGap.G; import net.iGap.R; +import net.iGap.Theme; import net.iGap.adapter.items.chat.ViewMaker; +import net.iGap.eventbus.EventListener; +import net.iGap.eventbus.EventManager; +import net.iGap.eventbus.socketMessages; import net.iGap.fragments.FragmentCall; import net.iGap.fragments.FragmentIgapSearch; import net.iGap.fragments.FragmentLanguage; import net.iGap.fragments.FragmentMain; import net.iGap.fragments.FragmentMediaPlayer; import net.iGap.fragments.FragmentNewGroup; -import net.iGap.fragments.FragmentQrCodeNewDevice; +import net.iGap.fragments.FragmentPayment; +import net.iGap.fragments.FragmentPaymentInquiry; import net.iGap.fragments.FragmentSetting; +import net.iGap.fragments.FragmentWalletAgrement; import net.iGap.fragments.FragmentiGapMap; import net.iGap.fragments.RegisteredContactsFragment; import net.iGap.fragments.SearchFragment; @@ -81,6 +86,7 @@ import net.iGap.helper.HelperLogout; import net.iGap.helper.HelperNotificationAndBadge; import net.iGap.helper.HelperPermission; +import net.iGap.helper.HelperPublicMethod; import net.iGap.helper.HelperUrl; import net.iGap.helper.ServiceContact; import net.iGap.interfaces.FinishActivity; @@ -99,6 +105,7 @@ import net.iGap.interfaces.OnGroupAvatarResponse; import net.iGap.interfaces.OnMapRegisterState; import net.iGap.interfaces.OnMapRegisterStateMain; +import net.iGap.interfaces.OnPayment; import net.iGap.interfaces.OnRefreshActivity; import net.iGap.interfaces.OnUnreadChange; import net.iGap.interfaces.OnUpdating; @@ -113,6 +120,7 @@ import net.iGap.libs.tabBar.NavigationTabStrip; import net.iGap.module.AndroidUtils; import net.iGap.module.AppUtils; +import net.iGap.module.ContactUtils; import net.iGap.module.EmojiTextViewE; import net.iGap.module.FileUtils; import net.iGap.module.LoginActions; @@ -134,8 +142,19 @@ import net.iGap.request.RequestSignalingGetConfiguration; import net.iGap.request.RequestUserInfo; import net.iGap.request.RequestUserSessionLogout; +import net.iGap.request.RequestUserVerifyNewDevice; +import net.iGap.request.RequestWalletGetAccessToken; +import net.iGap.request.RequestWalletIdMapping; import net.iGap.viewmodel.ActivityCallViewModel; -import net.iGap.viewmodel.FragmentSettingViewModel; +import net.iGap.viewmodel.FragmentPaymentInquiryViewModel; +import net.iGap.viewmodel.FragmentThemColorViewModel; + +import org.paygear.wallet.OnLanguageWallet; +import org.paygear.wallet.RaadApp; +import org.paygear.wallet.WalletActivity; +import org.paygear.wallet.fragment.PaymentHistoryFragment; +import org.paygear.wallet.model.Card; +import org.paygear.wallet.web.Web; import java.io.File; import java.io.IOException; @@ -143,6 +162,12 @@ import java.util.List; import io.realm.Realm; +import ir.pec.mpl.pecpayment.view.PaymentInitiator; +import ir.radsense.raadcore.model.Auth; +import ir.radsense.raadcore.web.WebBase; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; import static net.iGap.G.context; import static net.iGap.G.isSendContact; @@ -150,11 +175,14 @@ import static net.iGap.R.string.updating; import static net.iGap.fragments.FragmentiGapMap.mapUrls; -public class ActivityMain extends ActivityEnhanced implements OnUserInfoMyClient, OnUnreadChange, OnClientGetRoomListResponse, OnChatClearMessageResponse, OnChatSendMessageResponse, OnClientCondition, OnGroupAvatarResponse, DrawerLayout.DrawerListener, OnMapRegisterStateMain { +public class ActivityMain extends ActivityEnhanced implements OnUserInfoMyClient, OnPayment, OnUnreadChange, OnClientGetRoomListResponse, OnChatClearMessageResponse, OnChatSendMessageResponse, OnClientCondition, OnGroupAvatarResponse, DrawerLayout.DrawerListener, OnMapRegisterStateMain, EventListener { public static final String openChat = "openChat"; public static final String openMediaPlyer = "openMediaPlyer"; - + public static final int requestCodePaymentCharge = 198; + public static final int requestCodePaymentBill = 199; + public static final int requestCodeQrCode = 200; + public static final int requestCodeBarcode = 201; public static boolean isMenuButtonAddShown = false; public static boolean isOpenChatBeforeSheare = false; @@ -196,6 +224,8 @@ public class ActivityMain extends ActivityEnhanced implements OnUserInfoMyClient private ViewPager mViewPager; private ArrayList pages = new ArrayList(); private String phoneNumber; + private TextView itemCash; + private ViewGroup itemNavWallet; public static void setWeight(View view, int value) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); @@ -318,6 +348,7 @@ protected void onDestroy() { if (G.onAudioFocusChangeListener != null) { G.onAudioFocusChangeListener.onAudioFocusChangeListener(AudioManager.AUDIOFOCUS_LOSS); } + EventManager.getInstance().removeEventListener(EventManager.ON_ACCESS_TOKEN_RECIVE, this); } @@ -344,6 +375,10 @@ private void checkIntent(Intent intent) { new HelperGetDataFromOtherApp(intent); + if (intent.getAction() != null && intent.getAction().equals("net.iGap.activities.OPEN_ACCOUNT")) { + new HelperFragment(new FragmentSetting()).load(); + } + Bundle extras = intent.getExtras(); if (extras != null) { @@ -371,6 +406,15 @@ private void checkIntent(Intent intent) { @Override public void onCreate(Bundle savedInstanceState) { + + RaadApp.onLanguageWallet = new OnLanguageWallet() { + @Override + public String detectLanguage() { + return G.selectedLanguage; + } + }; + + // setTheme(R.style.AppThemeTranslucent); if (G.isFirstPassCode) { @@ -382,8 +426,17 @@ public void onCreate(Bundle savedInstanceState) { //} super.onCreate(savedInstanceState); - this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + RaadApp.paygearHistoryOpenChat = new PaymentHistoryFragment.PaygearHistoryOpenChat() { + @Override + public void paygearId(String id) { + new RequestWalletIdMapping().walletIdMapping(id); + } + }; + + EventManager.getInstance().addEventListener(EventManager.ON_ACCESS_TOKEN_RECIVE, this); + + this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); finishActivity = new FinishActivity() { @Override public void finishActivity() { @@ -392,7 +445,6 @@ public void finishActivity() { } }; - if (isNeedToRegister) { Intent intent = new Intent(this, ActivityRegisteration.class); @@ -416,7 +468,7 @@ public void finishActivity() { RealmUserInfo userInfo = getRealm().where(RealmUserInfo.class).findFirst(); - if (userInfo == null) { // user registered before + if (userInfo == null || !userInfo.getUserRegistrationState()) { // user registered before isNeedToRegister = true; Intent intent = new Intent(this, ActivityRegisteration.class); startActivity(intent); @@ -448,12 +500,6 @@ public void finishActivity() { editor.apply(); } } - SharedPreferences preferences = context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - if (G.isDarkTheme) { - this.setTheme(R.style.Material_blackCustom); - } else { - this.setTheme(R.style.Material_lightCustom); - } setContentView(R.layout.activity_main); drawer = (DrawerLayout) findViewById(R.id.drawer_layout); @@ -505,7 +551,7 @@ public void justOne() { lp.height = size; - desighnLayout(chatLayoutMode.none); + designLayout(chatLayoutMode.none); frameFragmentBack.setOnClickListener(new View.OnClickListener() { @Override @@ -518,7 +564,7 @@ public void onClick(View view) { G.iTowPanModDesinLayout = new ITowPanModDesinLayout() { @Override public void onLayout(chatLayoutMode mode) { - desighnLayout(mode); + designLayout(mode); } @Override @@ -595,6 +641,7 @@ public void onAppBarLayoutMove(AppBarLayout appBarLayout, int verticalOffset, bo initComponent(); + G.onPayment = this; sharedPreferences = getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); boolean isGetContactList = sharedPreferences.getBoolean(SHP_SETTING.KEY_GET_CONTACT, false); /** @@ -666,8 +713,6 @@ public void run() { initDrawerMenu(); - verifyAccount(); - checkKeepMedia(); @@ -701,6 +746,25 @@ public void run() { }; } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + switch (requestCode) { + case requestCodePaymentCharge: + case requestCodePaymentBill: + getPaymentResultCode(resultCode, data); + break; + case requestCodeQrCode: + IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data); + if (result.getContents() != null) { + new RequestUserVerifyNewDevice().verifyNewDevice(result.getContents()); + } + break; + } + } + private void checkKeepMedia() { final int keepMedia = sharedPreferences.getInt(SHP_SETTING.KEY_KEEP_MEDIA_NEW, 0); @@ -730,6 +794,87 @@ public void run() { } + private void getPaymentResultCode(int resultCode, Intent data) { + + if (G.onMplResult != null) { + G.onMplResult.onResult(false); + } + + String enData = "", message = "", status = "0"; + int errorType = 0, orderId = 0; + + switch (resultCode) { + case 1:// payment ok + enData = data.getStringExtra("enData"); + message = data.getStringExtra("message"); + status = String.valueOf(data.getIntExtra("status", 0)); + break; + case 2://payment error + errorType = data.getIntExtra("errorType", 0); + orderId = data.getIntExtra("OrderID", 0); + break; + case 3://bill payment ok + enData = data.getStringExtra("enData"); + message = data.getStringExtra("message"); + status = String.valueOf(data.getIntExtra("status", 0)); + break; + case 4://bill payment error + errorType = data.getIntExtra("errorType", 0); + break; + case 5://internal error payment + errorType = data.getIntExtra("errorType", 0); + orderId = data.getIntExtra("OrderID", 0); + break; + case 6://internal error bill + errorType = data.getIntExtra("errorType", 0); + break; + case 7:// charge payment ok + enData = data.getStringExtra("enData"); + message = data.getStringExtra("message"); + status = String.valueOf(data.getIntExtra("status", 0)); + break; + case 8: // charge payment error + errorType = data.getIntExtra("errorType", 0); + break; + case 9:// internal error charge + errorType = data.getIntExtra("errorType", 0); + break; + } + + if (errorType != 0) { + showErrorTypeMpl(errorType); + } + } + + private void showErrorTypeMpl(int errorType) { + String message = ""; + switch (errorType) { + case 2: + message = getString(R.string.time_out_error); + break; + case 1000: + message = getString(R.string.connection_error); + break; + case 1001: + message = getString(R.string.server_error); + break; + case 1002: + message = getString(R.string.network_error); + break; + case 201: + message = getString(R.string.dialog_canceled); + break; + case 2334: + message = getString(R.string.device_root); + break; + } + + if (message.length() > 0) { + HelperError.showSnackMessage(message, false); + } + } + + //******************************************************************************************************************************************* @Override @@ -746,13 +891,14 @@ public void onConfigurationChanged(Configuration newConfig) { } if (beforeState != G.isLandscape) { - desighnLayout(chatLayoutMode.none); + designLayout(chatLayoutMode.none); } } super.onConfigurationChanged(newConfig); + G.rotationState = newConfig.orientation; } //******************************************************************************************************************************************* @@ -886,12 +1032,14 @@ private void onSelectItem(int position) { findViewById(R.id.amr_ripple_search).setVisibility(View.VISIBLE); findViewById(R.id.am_btn_menu).setVisibility(View.GONE); + arcMenu.setVisibility(View.VISIBLE); setFabIcon(R.mipmap.plus); } else if (adapter.getItem(position) instanceof FragmentCall) { findViewById(R.id.amr_ripple_search).setVisibility(View.GONE); findViewById(R.id.am_btn_menu).setVisibility(View.VISIBLE); setFabIcon(R.drawable.ic_call_black_24dp); + arcMenu.setVisibility(View.VISIBLE); } if (arcMenu.isMenuOpened()) { @@ -1295,6 +1443,58 @@ public void onClick(View v) { } }); + + itemNavWallet = (ViewGroup) findViewById(R.id.lm_ll_wallet); + itemNavWallet.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (!G.isWalletRegister) { + new HelperFragment(FragmentWalletAgrement.newInstance(phoneNumber.substring(2))).load(); + lockNavigation(); + } else { + Intent intent = new Intent(ActivityMain.this, WalletActivity.class); + intent.putExtra("Language", "fa"); + intent.putExtra("Mobile", "0" + phoneNumber.substring(2)); + intent.putExtra("PrimaryColor", G.appBarColor); + intent.putExtra("DarkPrimaryColor", G.appBarColor); + intent.putExtra("AccentColor", G.appBarColor); + intent.putExtra("IS_DARK_THEME", G.isDarkTheme); + intent.putExtra(WalletActivity.LANGUAGE, G.selectedLanguage); + intent.putExtra(WalletActivity.PROGRESSBAR, G.progressColor); + intent.putExtra(WalletActivity.LINE_BORDER, G.lineBorder); + intent.putExtra(WalletActivity.BACKGROUND, G.backgroundTheme); + intent.putExtra(WalletActivity.BACKGROUND_2, G.backgroundTheme_2); + intent.putExtra(WalletActivity.TEXT_TITLE, G.textTitleTheme); + intent.putExtra(WalletActivity.TEXT_SUB_TITLE, G.textSubTheme); + startActivity(intent); + } + } + }); + + itemCash = (TextView) findViewById(R.id.cash); + if (G.isDarkTheme) { + itemCash.setTextColor(Color.parseColor(G.textTitleTheme)); + } else { + itemCash.setTextColor(Color.parseColor(G.appBarColor)); + } + + if (G.selectedCard != null) { + itemCash.setVisibility(View.VISIBLE); + itemCash.setText("" + getResources().getString(R.string.wallet_Your_credit) + " " + String.valueOf(G.selectedCard.cashOutBalance) + " " + getResources().getString(R.string.wallet_Reial)); + } else { + itemCash.setVisibility(View.GONE); + } + + ViewGroup itemNavPayment = (ViewGroup) findViewById(R.id.lm_ll_payment); + itemNavPayment.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new HelperFragment(FragmentPayment.newInstance()).load(); + lockNavigation(); + } + }); + + ViewGroup itemNavCall = (ViewGroup) findViewById(R.id.lm_ll_call); // gone or visible view call @@ -1364,7 +1564,12 @@ public void onClick(View v) { HelperPermission.getCameraPermission(ActivityMain.this, new OnGetPermission() { @Override public void Allow() throws IOException, IllegalStateException { - new HelperFragment(FragmentQrCodeNewDevice.newInstance()).setStateLoss(true).load(); + IntentIntegrator integrator = new IntentIntegrator(ActivityMain.this); + integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE); + integrator.setRequestCode(requestCodeQrCode); + integrator.setBeepEnabled(false); + integrator.setPrompt(""); + integrator.initiateScan(); } @Override @@ -1379,6 +1584,7 @@ public void deny() { closeDrawer(); } }); + final ToggleButton toggleButton = findViewById(R.id.st_txt_st_toggle_theme_dark); ViewGroup rootDarkTheme = (ViewGroup) findViewById(R.id.lt_txt_st_theme_dark); rootDarkTheme.setOnClickListener(new View.OnClickListener() { @@ -1389,17 +1595,28 @@ public void onClick(View v) { }); boolean checkedThemeDark = sharedPreferences.getBoolean(SHP_SETTING.KEY_THEME_DARK, false); - toggleButton.setChecked(checkedThemeDark); + toggleButton.setChecked(G.isDarkTheme); toggleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences.Editor editor = sharedPreferences.edit(); - if (toggleButton.isChecked()) { - FragmentSettingViewModel.setDarkTheme(editor); + + int themeColor = sharedPreferences.getInt(SHP_SETTING.KEY_THEME_COLOR, Theme.CUSTOM); + editor.putInt(SHP_SETTING.KEY_THEME_COLOR, Theme.DARK); + editor.putInt(SHP_SETTING.KEY_OLD_THEME_COLOR, themeColor); + editor.apply(); + Theme.setThemeColor(); + FragmentThemColorViewModel.resetApp(); } else { - FragmentSettingViewModel.setLightTheme(editor); + int themeColor = sharedPreferences.getInt(SHP_SETTING.KEY_OLD_THEME_COLOR, Theme.CUSTOM); + + editor.putInt(SHP_SETTING.KEY_THEME_COLOR, themeColor); + editor.apply(); + Theme.setThemeColor(); + FragmentThemColorViewModel.resetApp(); + } } }); @@ -1424,6 +1641,7 @@ public void onUserSessionLogout() { runOnUiThread(new Runnable() { @Override public void run() { + G.selectedCard = null; HelperLogout.logout(); } }); @@ -1439,7 +1657,6 @@ public void onTimeOut() { runOnUiThread(new Runnable() { @Override public void run() { - HelperError.showSnackMessage(getResources().getString(R.string.error), false); } @@ -1973,6 +2190,7 @@ private void setDrawerInfo(boolean updateFromServer) { TextView txtNavPhone = (TextView) findViewById(R.id.lm_txt_phone_number); txtNavName.setText(username); txtNavPhone.setText(phoneNumber); + setPhoneInquiry(phoneNumber); if (HelperCalander.isPersianUnicode) { txtNavPhone.setText(HelperCalander.convertToUnicodeFarsiNumber(txtNavPhone.getText().toString())); @@ -1985,6 +2203,46 @@ private void setDrawerInfo(boolean updateFromServer) { } } + private void setPhoneInquiry(String phone) { + + if (phone == null || phone.length() == 0) { + return; + } + + if (phone.startsWith("+98")) { + phone = phone.replace("+98", "0"); + } + + if (phone.startsWith("98")) { + phone = phone.replace("98", "0"); + } + + if (!phone.startsWith("0")) { + phone = "0" + phone; + } + + if (phone.length() < 5) { + return; + } + + FragmentPaymentInquiryViewModel.OperatorType operatorType = FragmentPaymentInquiryViewModel.MCI.get(phone.substring(0, 4)); + + if (operatorType != null) { + + TextView txtPhoneInquiry = findViewById(R.id.lm_txt_icon_phone_number_inquiry); + txtPhoneInquiry.setVisibility(View.VISIBLE); + + final String finalPhone = phone; + txtPhoneInquiry.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new HelperFragment(FragmentPaymentInquiry.newInstance(FragmentPaymentInquiryViewModel.OperatorType.mci, finalPhone)).setReplace(false).load(); + lockNavigation(); + } + }); + } + } + private void getUserInfo(final RealmUserInfo realmUserInfo) { if (!realmUserInfo.isValid()) { return; @@ -2055,7 +2313,7 @@ public void onBackPressed() { } } - desighnLayout(chatLayoutMode.none); + designLayout(chatLayoutMode.none); } } @@ -2088,7 +2346,7 @@ public void refresh(String changeLanguag) { } }; - desighnLayout(chatLayoutMode.none); + designLayout(chatLayoutMode.none); if (contentLoading != null) { @@ -2139,10 +2397,35 @@ public void onFinish() { G.onUserInfoMyClient = this; G.onMapRegisterStateMain = this; G.onUnreadChange = this; + G.onPayment = this; startService(new Intent(this, ServiceContact.class)); - HelperUrl.getLinkinfo(getIntent(), ActivityMain.this); + Intent intent = getIntent(); + String appLinkAction = intent.getAction(); + Uri appLinkData = intent.getData(); + if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null && appLinkData.getHost() != null && appLinkData.getHost().equals("com.android.contacts")) { + ContactUtils contactUtils = new ContactUtils(G.context, appLinkData); + String userId = contactUtils.retrieveNumber(); // we set retrieveNumber as userId + + if (intent.getType().equalsIgnoreCase("vnd.android.cursor.item/vnd.net.iGap.call")) { + + try { + check(Long.parseLong(userId)); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } else { + try { + HelperPublicMethod.goToChatRoom(Long.parseLong(userId), null, null); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + + } else { + HelperUrl.getLinkinfo(intent, ActivityMain.this); + } getIntent().setData(null); setDrawerInfo(false); if (drawer != null) { @@ -2163,6 +2446,8 @@ public void onFinish() { iconLock.setVisibility(View.GONE); } + onFinance(G.isMplActive, G.isWalletActive); + } private void enterPassword() { @@ -2204,6 +2489,7 @@ protected void onPause() { } } + @Override public void onChatClearMessage(final long roomId, long clearId) { //empty @@ -2255,16 +2541,32 @@ public void onAvatarAddError() { //******* GroupAvatar and ChannelAvatar + private void check(final long userId) { + if (G.userLogin) { + FragmentCall.call(userId, false); + } else { + G.handler.postDelayed(new Runnable() { + @Override + public void run() { + check(userId); + } + }, 1000); + } + + } + public void setImage() { HelperAvatar.getAvatar(G.userId, HelperAvatar.AvatarType.USER, true, new OnAvatarGet() { @Override public void onAvatarGet(final String avatarPath, long ownerId) { - G.handler.post(new Runnable() { - @Override - public void run() { - G.imageLoader.displayImage(AndroidUtils.suitablePath(avatarPath), imgNavImage); - } - }); + if (avatarPath != null) { + G.handler.post(new Runnable() { + @Override + public void run() { + G.imageLoader.displayImage(AndroidUtils.suitablePath(avatarPath), imgNavImage); + } + }); + } } @Override @@ -2490,36 +2792,7 @@ public void openNavigation() { //************************************************************* - public void verifyAccount() { - boolean bereitsAngelegt = false; - String accountType; - accountType = this.getPackageName(); - - AccountManager accountManager = AccountManager.get(getApplicationContext()); - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) { - return; - } - Account[] accounts = accountManager.getAccounts(); - for (int i = 0; i < accounts.length; i++) { - if ((accounts[i].type != null) && (accounts[i].type.contentEquals(accountType))) { - bereitsAngelegt = true; - } - } - - if (!bereitsAngelegt) { - AccountManager accMgr = AccountManager.get(this); - String password = ""; - - final Account account = new Account("" + phoneNumber, accountType); - try { - accMgr.addAccountExplicitly(account, password, null); - } catch (Exception e1) { - e1.getMessage(); - } - } - } // end of - - public void desighnLayout(final chatLayoutMode mode) { + public void designLayout(final chatLayoutMode mode) { G.handler.post(new Runnable() { @Override @@ -2576,6 +2849,7 @@ public void run() { protected void onStop() { super.onStop(); oldTime = System.currentTimeMillis(); + G.onPayment = null; } @Override @@ -2590,6 +2864,64 @@ public void run() { }); } + @Override + public void onChargeToken(int status, String token, int expireTime, String message) { + if (status == 0) { + Intent intent = new Intent(ActivityMain.this, PaymentInitiator.class); + intent.putExtra("Type", "3"); + intent.putExtra("Token", token); + startActivityForResult(intent, requestCodePaymentCharge); + } else { + if (G.onMplResult != null) { + G.onMplResult.onResult(true); + } + HelperError.showSnackMessage(message, false); + } + } + + @Override + public void onBillToken(int status, String token, int expireTime, String message) { + if (status == 0) { + Intent intent = new Intent(ActivityMain.this, PaymentInitiator.class); + intent.putExtra("Type", "2"); + intent.putExtra("Token", token); + startActivityForResult(intent, requestCodePaymentBill); + } else { + if (G.onMplResult != null) { + G.onMplResult.onResult(true); + } + HelperError.showSnackMessage(message, false); + } + } + + @Override + public void onFinance(final boolean mplActive, final boolean walletActive) { + + runOnUiThread(new Runnable() { + @Override + public void run() { + if (mplActive) { + findViewById(R.id.lm_ll_payment).setVisibility(View.VISIBLE); + } else { + findViewById(R.id.lm_ll_payment).setVisibility(View.GONE); + } + + if (walletActive) { + findViewById(R.id.lm_ll_wallet).setVisibility(View.VISIBLE); + } else { + findViewById(R.id.lm_ll_wallet).setVisibility(View.GONE); + } + + if (!G.isMplActive && !G.isWalletActive) { + findViewById(R.id.lm_view_Line).setVisibility(View.GONE); + } else { + findViewById(R.id.lm_view_Line).setVisibility(View.VISIBLE); + } + + } + }); + } + public enum MainAction { downScrool, clinetCondition } @@ -2632,4 +2964,72 @@ public int getCount() { } } + + private int retryConnectToWallet = 0; + + public void getUserCredit() { + + WebBase.apiKey = "5aa7e856ae7fbc00016ac5a01c65909797d94a16a279f46a4abb5faa"; + if (Auth.getCurrentAuth() != null) { + Web.getInstance().getWebService().getCredit(Auth.getCurrentAuth().getId()).enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + if (response.body() != null) { + retryConnectToWallet = 0; + if (response.body().size() > 0) + G.selectedCard = response.body().get(0); + + G.cardamount = G.selectedCard.cashOutBalance; + + if (G.selectedCard != null) { + itemCash.setVisibility(View.VISIBLE); + itemCash.setText("" + getResources().getString(R.string.wallet_Your_credit) + " " + String.valueOf(G.cardamount) + " " + getResources().getString(R.string.wallet_Reial)); + } + } + } + + @Override + public void onFailure(Call> call, Throwable t) { + + if (retryConnectToWallet < 3) { + Crashlytics.logException(new Exception(t.getMessage())); + getUserCredit(); + retryConnectToWallet++; + } + } + }); + } + } + + @Override + public void receivedMessage(int id, Object... message) { + + switch (id) { + case EventManager.ON_ACCESS_TOKEN_RECIVE: + int response = (int) message[0]; + switch (response) { + case socketMessages.SUCCESS: + new android.os.Handler(getMainLooper()).post(new Runnable() { + @Override + public void run() { + getUserCredit(); + retryConnectToWallet = 0; + } + }); + + break; + + case socketMessages.FAILED: + if (retryConnectToWallet < 3) { + new RequestWalletGetAccessToken().walletGetAccessToken(); + retryConnectToWallet++; + } + + break; + } + // backthread + + } + } + } diff --git a/app/src/main/java/net/iGap/activities/ActivityManageSpace.java b/app/src/main/java/net/iGap/activities/ActivityManageSpace.java index abef2ec..6293052 100644 --- a/app/src/main/java/net/iGap/activities/ActivityManageSpace.java +++ b/app/src/main/java/net/iGap/activities/ActivityManageSpace.java @@ -1,30 +1,17 @@ package net.iGap.activities; -import android.content.SharedPreferences; import android.databinding.DataBindingUtil; import android.os.Bundle; -import net.iGap.G; import net.iGap.R; import net.iGap.databinding.ActivityManageSpaceBinding; import net.iGap.libs.rippleeffect.RippleView; -import net.iGap.module.SHP_SETTING; import net.iGap.viewmodel.ActivityManageSpaceViewModel; -import static net.iGap.G.context; - public class ActivityManageSpace extends ActivityEnhanced { @Override public void onCreate(Bundle savedInstanceState) { - - SharedPreferences preferences = context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - if (G.isDarkTheme) { - this.setTheme(R.style.Material_blackCustom); - } else { - this.setTheme(R.style.Material_lightCustom); - } - super.onCreate(savedInstanceState); ActivityManageSpaceBinding activityManageSpaceBinding = DataBindingUtil.setContentView(this, R.layout.activity_manage_space); ActivityManageSpaceViewModel activityManageSpaceViewModel = new ActivityManageSpaceViewModel(this); diff --git a/app/src/main/java/net/iGap/activities/ActivityPopUpNotification.java b/app/src/main/java/net/iGap/activities/ActivityPopUpNotification.java index a5764cc..00bea81 100644 --- a/app/src/main/java/net/iGap/activities/ActivityPopUpNotification.java +++ b/app/src/main/java/net/iGap/activities/ActivityPopUpNotification.java @@ -46,6 +46,7 @@ import net.iGap.G; import net.iGap.R; +import net.iGap.Theme; import net.iGap.interfaces.IPopUpListener; import net.iGap.interfaces.OnVoiceRecord; import net.iGap.libs.rippleeffect.RippleView; @@ -213,8 +214,30 @@ private void changeEmojiButtonImageResource(@StringRes int drawableResourceId) { btnSmileButton.setText(drawableResourceId); } + + private void setUpEmojiPopup() { - emojiPopup = EmojiPopup.Builder.fromRootView(findViewById(R.id.ac_ll_parent_notification)).setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() { + switch (G.themeColor) { + case Theme.BLUE_GREY_COMPLETE: + case Theme.INDIGO_COMPLETE: + case Theme.BROWN_COMPLETE: + case Theme.GREY_COMPLETE: + case Theme.TEAL_COMPLETE: + case Theme.DARK: + + setEmojiColor(G.backgroundTheme_2, G.textTitleTheme, G.textTitleTheme); + break; + default: + setEmojiColor("#eceff1", "#61000000", "#61000000"); + + + } + + } + + private void setEmojiColor(String BackgroundColor, String iconColor, String dividerColor) { + + emojiPopup = emojiPopup = EmojiPopup.Builder.fromRootView(findViewById(R.id.ac_ll_parent_notification)).setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() { @Override public void onEmojiBackspaceClick(View v) { @@ -240,9 +263,16 @@ public void onEmojiPopupDismiss() { public void onKeyboardClose() { emojiPopup.dismiss(); } - }).build(edtChat); + }) + .setBackgroundColor(Color.parseColor(BackgroundColor)) + .setIconColor(Color.parseColor(iconColor)) + .setDividerColor(Color.parseColor(dividerColor)) + .build(edtChat); + } + + private void setImageAndTextAppBar(int position) { if (mList.isEmpty() || position > mList.size() - 1 || position < 0) { return; diff --git a/app/src/main/java/net/iGap/activities/ActivityTrimVideo.java b/app/src/main/java/net/iGap/activities/ActivityTrimVideo.java index 7854e06..2baef4a 100644 --- a/app/src/main/java/net/iGap/activities/ActivityTrimVideo.java +++ b/app/src/main/java/net/iGap/activities/ActivityTrimVideo.java @@ -18,8 +18,11 @@ import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; +import android.view.View; +import android.widget.ProgressBar; import android.widget.TextView; +import net.iGap.G; import net.iGap.R; import java.io.File; @@ -33,11 +36,11 @@ public class ActivityTrimVideo extends ActivityEnhanced implements OnTrimVideoLi int videoWidth = 641; int videoHeight = 481; private String path; - private long originalSize; - private long duration; + private int duration; private TextView txtDetail; private TextView txtTime; private TextView txtSize; + private ProgressBar progressBar; @Override public void onCreate(Bundle savedInstanceState) { @@ -58,43 +61,64 @@ public void onCreate(Bundle savedInstanceState) { } } - getResolutionVideo(path); - durationVideo(path); + setInfo(path); K4LVideoTrimmer videoTrimmer = (K4LVideoTrimmer) findViewById(R.id.timeLine); + progressBar = (ProgressBar) findViewById(R.id.fvt_progress); if (videoTrimmer != null) { videoTrimmer.setVideoURI(Uri.parse(path)); - videoTrimmer.setMaxDuration((int) duration); + videoTrimmer.setMaxDuration(duration); videoTrimmer.setOnTrimVideoListener(this); - videoTrimmer.setDestinationPath(path); + videoTrimmer.setDestinationPath(G.DIR_VIDEOS + "/"); videoTrimmer.setVideoInformationVisibility(true); } } - private void durationVideo(String path) { + private void setInfo(String path) { + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { - if (path != null) { - File file = new File(path); - originalSize = file.length(); - - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setDataSource(file.toString()); // Enter Full File Path Here - String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); - duration = Long.parseLong(time); - int seconds = (int) ((duration) / 1000); - int minutes = seconds / 60; - seconds = seconds % 60; + retriever.setDataSource(path); + + File file = new File(path); + if (file.exists()) { + txtSize.setText("," + net.iGap.module.FileUtils.formatFileSize((long) file.length())); + } + + String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + if (time != null && time.length() > 0) { + duration = ((Integer.parseInt(time)) / 1000) + 1; + int minutes = duration / 60; + int seconds = duration % 60; txtTime.setText("," + String.format("%02d", minutes) + ":" + String.format("%02d", seconds)); + } + + Bitmap bmp = retriever.getFrameAtTime(); - txtSize.setText("," + net.iGap.module.FileUtils.formatFileSize((long) originalSize)); + if (bmp != null) { + videoHeight = bmp.getHeight(); + videoWidth = bmp.getWidth(); } } catch (IllegalArgumentException e) { e.printStackTrace(); + } catch (RuntimeException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + retriever.release(); } + txtDetail.setText(videoWidth + "X" + videoHeight); } @Override public void onTrimStarted() { + + runOnUiThread(new Runnable() { + @Override + public void run() { + progressBar.setVisibility(View.VISIBLE); + } + }); } @Override @@ -140,22 +164,5 @@ public void onVideoPrepared() { } - private void getResolutionVideo(String path) { - try { - MediaMetadataRetriever re = new MediaMetadataRetriever(); - Bitmap bmp = null; - re.setDataSource(path); - bmp = re.getFrameAtTime(); - videoHeight = bmp.getHeight(); - videoWidth = bmp.getWidth(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (RuntimeException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - txtDetail.setText(videoWidth + "X" + videoHeight); - } } diff --git a/app/src/main/java/net/iGap/adapter/AdapterBottomSheet.java b/app/src/main/java/net/iGap/adapter/AdapterBottomSheet.java index cdbc418..2fddcea 100644 --- a/app/src/main/java/net/iGap/adapter/AdapterBottomSheet.java +++ b/app/src/main/java/net/iGap/adapter/AdapterBottomSheet.java @@ -76,12 +76,12 @@ public void onClick(View v) { if (holder.checkBoxSelect.isChecked()) { holder.checkBoxSelect.setChecked(false); holder.checkBoxSelect.setUnCheckColor(G.context.getResources().getColor(R.color.transparent)); - FragmentChat.onPathAdapterBottomSheet.path(mList.getPath(), false, false); + FragmentChat.onPathAdapterBottomSheet.path(mList.getPath(), false, false, mList, mList.getId()); mList.setSelected(true); } else { holder.checkBoxSelect.setChecked(true); holder.checkBoxSelect.setUnCheckColor(G.context.getResources().getColor(R.color.green)); - FragmentChat.onPathAdapterBottomSheet.path(mList.getPath(), true, false); + FragmentChat.onPathAdapterBottomSheet.path(mList.getPath(), true, false, mList, mList.getId()); mList.setSelected(false); } } @@ -93,12 +93,12 @@ public void onClick(View v) { if (holder.checkBoxSelect.isChecked()) { holder.checkBoxSelect.setChecked(false); holder.checkBoxSelect.setUnCheckColor(G.context.getResources().getColor(R.color.transparent)); - FragmentChat.onPathAdapterBottomSheet.path(mList.getPath(), false, true); + FragmentChat.onPathAdapterBottomSheet.path(mList.getPath(), false, true, mList, mList.getId()); mList.setSelected(false); } else { holder.checkBoxSelect.setChecked(true); holder.checkBoxSelect.setUnCheckColor(G.context.getResources().getColor(R.color.green)); - FragmentChat.onPathAdapterBottomSheet.path(mList.getPath(), true, true); + FragmentChat.onPathAdapterBottomSheet.path(mList.getPath(), true, true, mList, mList.getId()); mList.setSelected(true); } diff --git a/app/src/main/java/net/iGap/adapter/AdapterChatBackground.java b/app/src/main/java/net/iGap/adapter/AdapterChatBackground.java index 3d486ea..601c452 100644 --- a/app/src/main/java/net/iGap/adapter/AdapterChatBackground.java +++ b/app/src/main/java/net/iGap/adapter/AdapterChatBackground.java @@ -81,7 +81,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) final String path = G.DIR_CHAT_BACKGROUND + "/" + "thumb_" + pf.getCacheId() + "_" + pf.getName(); if (!new File(path).exists()) { - HelperDownloadFile.startDownload(System.currentTimeMillis() + "", pf.getToken(), pf.getPublicUrl(), pf.getCacheId(), pf.getName(), pf.getSmallThumbnail().getSize(), ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL, path, 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(System.currentTimeMillis() + "", pf.getToken(), pf.getPublicUrl(), pf.getCacheId(), pf.getName(), pf.getSmallThumbnail().getSize(), ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL, path, 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(String mPath, int progress) { if (progress == 100) { @@ -166,7 +166,7 @@ public void run() { } }); - HelperDownloadFile.startDownload(System.currentTimeMillis() + "", pf.getToken(), pf.getPublicUrl(), pf.getCacheId(), pf.getName(), pf.getSize(), ProtoFileDownload.FileDownload.Selector.FILE, path, 2, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(System.currentTimeMillis() + "", pf.getToken(), pf.getPublicUrl(), pf.getCacheId(), pf.getName(), pf.getSize(), ProtoFileDownload.FileDownload.Selector.FILE, path, 2, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(String mPath, final int progress) { messageProgress.post(new Runnable() { diff --git a/app/src/main/java/net/iGap/adapter/MessagesAdapter.java b/app/src/main/java/net/iGap/adapter/MessagesAdapter.java index d31a87a..030e49d 100644 --- a/app/src/main/java/net/iGap/adapter/MessagesAdapter.java +++ b/app/src/main/java/net/iGap/adapter/MessagesAdapter.java @@ -24,6 +24,7 @@ import net.iGap.R; import net.iGap.adapter.items.chat.AbstractMessage; import net.iGap.adapter.items.chat.LogItem; +import net.iGap.adapter.items.chat.LogWallet; import net.iGap.adapter.items.chat.TimeItem; import net.iGap.helper.HelperUrl; import net.iGap.interfaces.IMessageItem; @@ -50,7 +51,7 @@ public class MessagesAdapter extends FastItemAdapt @Override public boolean onLongClick(View v, IAdapter adapter, Item item, int position) { - if (item instanceof TimeItem || item instanceof LogItem) { + if (item instanceof TimeItem || item instanceof LogItem || item instanceof LogWallet) { if (item.isSelected()) v.performLongClick(); } else { if (iMessageItem != null && item.mMessage != null && item.mMessage.senderID != null && !item.mMessage.senderID.equalsIgnoreCase("-1")) { @@ -87,6 +88,11 @@ public MessagesAdapter(OnChatMessageSelectionChanged OnChatMessageSelectio withOnClickListener(new OnClickListener() { @Override public boolean onClick(View v, IAdapter adapter, Item item, int position) { + + if ((item instanceof LogWallet)) { + return false; + } + if (getSelectedItems().size() == 0) { if (iMessageItem != null && item.mMessage != null && item.mMessage.senderID != null && !item.mMessage.senderID.equalsIgnoreCase("-1")) { if (item.mMessage.status.equalsIgnoreCase(ProtoGlobal.RoomMessageStatus.SENDING.toString())) { diff --git a/app/src/main/java/net/iGap/adapter/items/chat/AbstractMessage.java b/app/src/main/java/net/iGap/adapter/items/chat/AbstractMessage.java index 4645c88..8a6cd1e 100644 --- a/app/src/main/java/net/iGap/adapter/items/chat/AbstractMessage.java +++ b/app/src/main/java/net/iGap/adapter/items/chat/AbstractMessage.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.adapter.items.chat; @@ -14,6 +14,7 @@ import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.GradientDrawable; import android.support.annotation.CallSuper; import android.support.v4.content.ContextCompat; import android.support.v4.util.ArrayMap; @@ -203,7 +204,7 @@ private void addLayoutTime(VH holder) { public void bindView(final VH holder, List payloads) { super.bindView(holder, payloads); - if (holder instanceof ProgressWaiting.ViewHolder || holder instanceof UnreadMessage.ViewHolder || holder instanceof LogItem.ViewHolder || holder instanceof TimeItem.ViewHolder) { + if (holder instanceof ProgressWaiting.ViewHolder || holder instanceof UnreadMessage.ViewHolder || holder instanceof LogWallet.ViewHolder || holder instanceof LogItem.ViewHolder || holder instanceof TimeItem.ViewHolder) { return; } @@ -349,7 +350,7 @@ public void run() { TextView txtTime = (TextView) holder.itemView.findViewById(R.id.cslr_txt_time); if (txtTime != null) { - txtTime.setTextColor(Color.parseColor(G.textTitleTheme)); + txtTime.setTextColor(Color.parseColor(G.textBubble)); txtTime.setText(HelperCalander.getClocktime(mMessage.time, false)); if (HelperCalander.isPersianUnicode) { @@ -655,11 +656,13 @@ protected void updateLayoutForReceive(VH holder) { ViewGroup frameLayout = (ViewGroup) holder.itemView.findViewById(R.id.mainContainer); ImageView imgTick = (ImageView) holder.itemView.findViewById(R.id.cslr_txt_tic); TextView messageText = (TextView) holder.itemView.findViewById(R.id.messageSenderTextMessage); - LinearLayout timeLayout = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer).getParent(); + + LinearLayout root = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer); + LinearLayout timeLayout = (LinearLayout) root.getParent(); timeLayout.setGravity(Gravity.LEFT); if (messageText != null) { - messageText.setTextColor(Color.parseColor(G.textTitleTheme)); + messageText.setTextColor(Color.parseColor(G.textBubble)); } // ProtoGlobal.RoomMessageType messageType = mMessage.forwardedFrom == null ? mMessage.messageType : mMessage.forwardedFrom.getMessageType(); @@ -672,7 +675,7 @@ protected void updateLayoutForReceive(VH holder) { ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).gravity = Gravity.LEFT; - ((LinearLayout.LayoutParams) holder.itemView.findViewById(R.id.contentContainer).getLayoutParams()).gravity = Gravity.LEFT; + ((LinearLayout.LayoutParams) root.getLayoutParams()).gravity = Gravity.LEFT; if (G.isDarkTheme) { ((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangel_white_round_dark); @@ -684,6 +687,10 @@ protected void updateLayoutForReceive(VH holder) { * add main layout margin to prevent getting match parent completely * set to mainContainer not itemView because of selecting item foreground */ + + GradientDrawable circleDarkColor = (GradientDrawable) ((View) root.getParent()).getBackground(); + circleDarkColor.setColor(Color.parseColor(G.bubbleChatReceive)); + ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).leftMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp10); ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).rightMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp28); } @@ -706,10 +713,11 @@ protected void updateLayoutForSend(VH holder) { ViewGroup frameLayout = (ViewGroup) holder.itemView.findViewById(R.id.mainContainer); ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).gravity = Gravity.RIGHT; + LinearLayout root = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer); - ((LinearLayout.LayoutParams) holder.itemView.findViewById(R.id.contentContainer).getLayoutParams()).gravity = Gravity.RIGHT; + ((LinearLayout.LayoutParams) root.getLayoutParams()).gravity = Gravity.RIGHT; - LinearLayout timeLayout = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer).getParent(); + LinearLayout timeLayout = (LinearLayout) root.getParent(); timeLayout.setGravity(Gravity.RIGHT); ImageView imgTick = (ImageView) holder.itemView.findViewById(R.id.cslr_txt_tic); @@ -717,14 +725,14 @@ protected void updateLayoutForSend(VH holder) { // TextView iconHearing = (TextView) holder.itemView.findViewById(R.id.cslr_txt_hearing); if (messageText != null) { - messageText.setTextColor(Color.parseColor(G.textTitleTheme)); + messageText.setTextColor(Color.parseColor(G.textBubble)); } // ProtoGlobal.RoomMessageType messageType = mMessage.forwardedFrom == null ? mMessage.messageType : mMessage.forwardedFrom.getMessageType(); if (ProtoGlobal.RoomMessageStatus.valueOf(mMessage.status) == ProtoGlobal.RoomMessageStatus.SEEN) { if (G.isDarkTheme) { setTextColor(imgTick, R.color.iGapColor); - }else { + } else { setTextColor(imgTick, R.color.backgroundColorCall2); } @@ -732,24 +740,24 @@ protected void updateLayoutForSend(VH holder) { // iconHearing.setVisibility(View.VISIBLE); if (G.isDarkTheme) { setTextColor(imgTick, R.color.iGapColor); - }else { + } else { setTextColor(imgTick, R.color.backgroundColorCall2); } imgTick.setVisibility(View.VISIBLE); } else { - - if (G.isDarkTheme) { - setTextColor(imgTick, R.color.white); - } else { - setTextColor(imgTick, R.color.colorOldBlack); - } +// setTextColor(imgTick, Color.parseColor(G.txtIconCheck)); + imgTick.setColorFilter(Color.parseColor(G.txtIconCheck)); } + + if (G.isDarkTheme) { ((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangle_send_round_color_dark); } else { ((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangle_send_round_color); } + GradientDrawable circleDarkColor = (GradientDrawable) ((View) root.getParent()).getBackground(); + circleDarkColor.setColor(Color.parseColor(G.bubbleChatSend)); /** * add main layout margin to prevent getting match parent completely @@ -818,32 +826,24 @@ public void onClick(View v) { ((EmojiTextViewE) replayView.findViewById(R.id.chslr_txt_replay_message)).setText(forwardMessage); if (mMessage.isSenderMe() && type != ProtoGlobal.Room.Type.CHANNEL) { - if (G.isDarkTheme) { - replayView.setBackgroundResource(R.drawable.rectangle_reply_sender_round_color_dark); - replyFrom.setTextColor(Color.parseColor(G.textTitleTheme)); - replayMessage.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - replayView.setBackgroundResource(R.drawable.rectangle_reply_sender_round_color); - replyFrom.setTextColor(holder.itemView.getResources().getColor(R.color.colorOldBlack)); - replayMessage.setTextColor(holder.itemView.getResources().getColor(R.color.replay_message_text)); - } - //holder.itemView.findViewById(R.id.verticalLine).setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.messageBox_sendColor)); + replayView.setBackgroundResource(R.drawable.rectangle_reply_sender_round_color); +// + GradientDrawable circleDarkColor = (GradientDrawable) replayView.getBackground(); + circleDarkColor.setColor(Color.parseColor(G.backgroundTheme_2)); + + replyFrom.setTextColor(Color.parseColor(G.textBubble)); + replayMessage.setTextColor(Color.parseColor(G.textBubble)); } else { - if (G.isDarkTheme) { - replayView.setBackgroundResource(R.drawable.rectangle_reply_recive_round_color_dark); - // holder.itemView.findViewById(R.id.verticalLine).setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.messageBox_receiveColor)); - replyFrom.setTextColor(Color.parseColor(G.textTitleTheme)); - replayMessage.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - replayView.setBackgroundResource(R.drawable.rectangle_reply_recive_round_color); - // holder.itemView.findViewById(R.id.verticalLine).setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.messageBox_receiveColor)); - replyFrom.setTextColor(holder.itemView.getResources().getColor(R.color.colorOldBlack)); - replayMessage.setTextColor(holder.itemView.getResources().getColor(R.color.replay_message_text)); - } + replayView.setBackgroundResource(R.drawable.rectangle_reply_recive_round_color); + + GradientDrawable circleDarkColor = (GradientDrawable) replayView.getBackground(); + circleDarkColor.setColor(Color.parseColor(G.backgroundTheme_2)); + replyFrom.setTextColor(Color.parseColor(G.textBubble)); + replayMessage.setTextColor(Color.parseColor(G.textBubble)); } @@ -894,7 +894,7 @@ protected void forwardMessageIfNeeded(VH holder, Realm realm) { public void onClick(View v) { if (mMessage.username.length() > 0) { - HelperUrl.checkUsernameAndGoToRoom(mMessage.username, HelperUrl.ChatEntry.profile); + HelperUrl.checkUsernameAndGoToRoomWithMessageId(mMessage.username, HelperUrl.ChatEntry.profile, (mMessage.forwardedFrom.getMessageId() * (-1))); } } }); @@ -936,7 +936,7 @@ public void onClick(View v) { if (realmRoom != null) { txtForwardFrom.setText(realmRoom.getTitle()); if (mMessage.isSenderMe()) { - txtForwardFrom.setTextColor(Color.parseColor(G.textTitleTheme)); + txtForwardFrom.setTextColor(Color.parseColor(G.textBubble)); } else { txtForwardFrom.setTextColor(G.context.getResources().getColor(R.color.iGapColor)); } @@ -975,7 +975,7 @@ public void onClick(View v) { txtForwardFrom.setText(realmRoom1.getTitle()); if (mMessage.isSenderMe()) { - txtForwardFrom.setTextColor(Color.parseColor(G.textTitleTheme)); + txtForwardFrom.setTextColor(Color.parseColor(G.textBubble)); } else { txtForwardFrom.setTextColor(G.context.getResources().getColor(R.color.iGapColor)); } @@ -1043,7 +1043,7 @@ public void onMessageProgressClick(MessageProgress progress) { private void checkAutoDownload(final VH holder, final RealmAttachment attachment, Context context, HelperCheckInternetConnection.ConnectivityType connectionMode) { - if (HelperDownloadFile.manuallyStoppedDownload.contains(attachment.getCacheId())) { // for avoid from reDownload in autoDownload state , after that user manually stopped download. + if (HelperDownloadFile.getInstance().manuallyStoppedDownload.contains(attachment.getCacheId())) { // for avoid from reDownload in autoDownload state , after that user manually stopped download. return; } @@ -1358,8 +1358,8 @@ private void forOnCLick(VH holder, RealmAttachment attachment) { } else { messageClickListener.onUploadOrCompressCancel(progress, mMessage, holder.getAdapterPosition(), SendingStep.UPLOADING); } - } else if (HelperDownloadFile.isDownLoading(attachment.getCacheId())) { - HelperDownloadFile.stopDownLoad(attachment.getCacheId()); + } else if (HelperDownloadFile.getInstance().isDownLoading(attachment.getCacheId())) { + HelperDownloadFile.getInstance().stopDownLoad(attachment.getCacheId()); } else { if (thumbnail != null) { thumbnail.setVisibility(View.VISIBLE); @@ -1424,7 +1424,7 @@ private void downLoadThumbnail(final VH holder, final RealmAttachment attachment if (token != null && token.length() > 0 && size > 0) { - HelperDownloadFile.startDownload(mMessage.messageID, token, url, attachment.getCacheId(), name, size, selector, "", 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(mMessage.messageID, token, url, attachment.getCacheId(), name, size, selector, "", 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, int progress) { @@ -1461,7 +1461,7 @@ void downLoadFile(final VH holder, final RealmAttachment attachment, int priorit return; } - boolean _isDownloading = HelperDownloadFile.isDownLoading(attachment.getCacheId()); + boolean _isDownloading = HelperDownloadFile.getInstance().isDownLoading(attachment.getCacheId()); final MessageProgress progressBar = (MessageProgress) holder.itemView.findViewById(R.id.progress); AppUtils.setProgresColor(progressBar.progressBar); @@ -1483,7 +1483,7 @@ void downLoadFile(final VH holder, final RealmAttachment attachment, int priorit progressBar.withDrawable(R.drawable.ic_cancel, false); - HelperDownloadFile.startDownload(mMessage.messageID, token, url, attachment.getCacheId(), name, size, selector, _path, priority, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(mMessage.messageID, token, url, attachment.getCacheId(), name, size, selector, _path, priority, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, final int progress) { @@ -1661,7 +1661,7 @@ private void checkForDownloading(VH holder, RealmAttachment attachment) { MessageProgress progress = (MessageProgress) holder.itemView.findViewById(R.id.progress); AppUtils.setProgresColor(progress.progressBar); - if (HelperDownloadFile.isDownLoading(attachment.getCacheId())) { + if (HelperDownloadFile.getInstance().isDownLoading(attachment.getCacheId())) { hideThumbnailIf(holder); downLoadFile(holder, attachment, 0); diff --git a/app/src/main/java/net/iGap/adapter/items/chat/AudioItem.java b/app/src/main/java/net/iGap/adapter/items/chat/AudioItem.java index c482a33..fbac25a 100644 --- a/app/src/main/java/net/iGap/adapter/items/chat/AudioItem.java +++ b/app/src/main/java/net/iGap/adapter/items/chat/AudioItem.java @@ -12,6 +12,7 @@ import android.graphics.Color; import android.graphics.PorterDuff; +import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; @@ -271,6 +272,8 @@ public boolean onTouch(View v, MotionEvent event) { audioBoxView.setBackgroundResource(R.drawable.green_bg_rounded_corner); } + GradientDrawable circleDarkColor = (GradientDrawable) audioBoxView.getBackground(); + circleDarkColor.setColor(Color.parseColor(G.bubbleChatMusic)); //if ((mMessage.forwardedFrom != null && mMessage.forwardedFrom.getForwardMessage() != null && mMessage.forwardedFrom.getForwardMessage().getMessage() != null && !TextUtils.isEmpty(mMessage.forwardedFrom.getForwardMessage().getMessage())) || !TextUtils.isEmpty(mMessage.messageText)) { // audioBoxView.setBackgroundResource(R.drawable.green_bg_rounded_corner); @@ -286,7 +289,9 @@ public boolean onTouch(View v, MotionEvent event) { MusicPlayer.onCompleteChat = holder.complete; holder.musicSeekbar.setProgress(MusicPlayer.musicProgress); - holder.txt_Timer.setText(MusicPlayer.strTimer + "/" + MusicPlayer.musicTime); + if (MusicPlayer.musicProgress > 0) { + holder.txt_Timer.setText(MusicPlayer.strTimer + "/" + MusicPlayer.musicTime); + } holder.mTimeMusic = MusicPlayer.musicTime; diff --git a/app/src/main/java/net/iGap/adapter/items/chat/FileItem.java b/app/src/main/java/net/iGap/adapter/items/chat/FileItem.java index a4ca417..d161a7d 100644 --- a/app/src/main/java/net/iGap/adapter/items/chat/FileItem.java +++ b/app/src/main/java/net/iGap/adapter/items/chat/FileItem.java @@ -116,13 +116,16 @@ protected void updateLayoutForSend(ViewHolder holder) { @Override protected void updateLayoutForReceive(ViewHolder holder) { super.updateLayoutForReceive(holder); - if (G.isDarkTheme) { - holder.cslf_txt_file_name.setTextColor(Color.parseColor(G.textTitleTheme)); - holder.cslf_txt_file_size.setTextColor(Color.parseColor(G.textSubTheme)); - } else { - holder.cslf_txt_file_name.setTextColor(holder.itemView.getResources().getColor(R.color.colorOldBlack)); - holder.cslf_txt_file_size.setTextColor(holder.itemView.getResources().getColor(R.color.colorOldBlack)); - } +// if (G.isDarkTheme) { +// holder.cslf_txt_file_name.setTextColor(Color.parseColor(G.textTitleTheme)); +// holder.cslf_txt_file_size.setTextColor(Color.parseColor(G.textSubTheme)); +// } else { +// holder.cslf_txt_file_name.setTextColor(holder.itemView.getResources().getColor(R.color.colorOldBlack)); +// holder.cslf_txt_file_size.setTextColor(holder.itemView.getResources().getColor(R.color.colorOldBlack)); +// } +// + holder.cslf_txt_file_name.setTextColor(Color.parseColor(G.textBubble)); + holder.cslf_txt_file_size.setTextColor(Color.parseColor(G.textBubble)); } diff --git a/app/src/main/java/net/iGap/adapter/items/chat/LocationItem.java b/app/src/main/java/net/iGap/adapter/items/chat/LocationItem.java index 1118fda..2479ad2 100644 --- a/app/src/main/java/net/iGap/adapter/items/chat/LocationItem.java +++ b/app/src/main/java/net/iGap/adapter/items/chat/LocationItem.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.adapter.items.chat; @@ -23,8 +23,10 @@ import net.iGap.interfaces.IMessageItem; import net.iGap.interfaces.OnGetPermission; import net.iGap.module.AndroidUtils; +import net.iGap.module.AppUtils; import net.iGap.module.ReserveSpaceRoundedImageView; import net.iGap.proto.ProtoGlobal; +import net.iGap.realm.RealmRoom; import net.iGap.realm.RealmRoomMessageLocation; import java.io.File; @@ -76,33 +78,17 @@ public void bindView(final ViewHolder holder, List payloads) { } if (item != null) { - if (item.getImagePath() != null && new File(item.getImagePath()).exists()) { - G.imageLoader.displayImage(AndroidUtils.suitablePath(item.getImagePath()), holder.imgMapPosition); + String path = AppUtils.getLocationPath(item.getLocationLat(), item.getLocationLong()); + + if (new File(path).exists()) { + G.imageLoader.displayImage(AndroidUtils.suitablePath(path), holder.imgMapPosition); } else { + RealmRoomMessageLocation finalItem1 = item; FragmentMap.loadImageFromPosition(item.getLocationLat(), item.getLocationLong(), new FragmentMap.OnGetPicture() { @Override public void getBitmap(Bitmap bitmap) { holder.imgMapPosition.setImageBitmap(bitmap); - - final String savedPath = FragmentMap.saveBitmapToFile(bitmap); - - Realm realm = Realm.getDefaultInstance(); - realm.executeTransaction(new Realm.Transaction() { - @Override - public void execute(Realm realm) { - - if (mMessage.forwardedFrom != null) { - if (mMessage.forwardedFrom.getLocation() != null) { - mMessage.forwardedFrom.getLocation().setImagePath(savedPath); - } - } else { - if (mMessage.location != null) { - mMessage.location.setImagePath(savedPath); - } - } - } - }); - realm.close(); + AppUtils.saveMapToFile(bitmap, finalItem1.getLocationLat(), finalItem1.getLocationLong()); } }); } @@ -113,13 +99,17 @@ public void execute(Realm realm) { public void onClick(View v) { try { HelperPermission.getLocationPermission(G.currentActivity, new OnGetPermission() { + @Override public void Allow() { G.handler.post(new Runnable() { @Override public void run() { - FragmentMap fragment = FragmentMap.getInctance(finalItem.getLocationLat(), finalItem.getLocationLong(), FragmentMap.Mode.seePosition); + + FragmentMap fragment = FragmentMap.getInctance(finalItem.getLocationLat(), finalItem.getLocationLong(), FragmentMap.Mode.seePosition, + RealmRoom.detectType(mMessage.roomId).getNumber(), mMessage.roomId, mMessage.senderID); new HelperFragment(fragment).setReplace(false).load(); + } }); } diff --git a/app/src/main/java/net/iGap/adapter/items/chat/LogWallet.java b/app/src/main/java/net/iGap/adapter/items/chat/LogWallet.java new file mode 100644 index 0000000..4230a71 --- /dev/null +++ b/app/src/main/java/net/iGap/adapter/items/chat/LogWallet.java @@ -0,0 +1,159 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.adapter.items.chat; + +import android.support.v7.widget.RecyclerView; +import android.text.format.DateUtils; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.helper.HelperCalander; +import net.iGap.helper.HelperRadius; +import net.iGap.interfaces.IMessageItem; +import net.iGap.module.ReserveSpaceRoundedImageView; +import net.iGap.module.enums.LocalFileType; +import net.iGap.proto.ProtoGlobal; +import net.iGap.realm.RealmRegisteredInfo; + +import java.util.Calendar; +import java.util.List; + +import io.realm.Realm; + +import static net.iGap.module.AndroidUtils.suitablePath; + +public class LogWallet extends AbstractMessage { + private Realm mRealm; + + public LogWallet(Realm realmChat, ProtoGlobal.Room.Type type, IMessageItem messageClickListener) { + super(realmChat, true, type, messageClickListener); + } + + @Override + public int getType() { + return R.id.chatSubLayoutLogWallet; + } + + @Override + public int getLayoutRes() { + return R.layout.chat_sub_layout_log_wallet; + } + + + @Override + public void bindView(final ViewHolder holder, List payloads) { + super.bindView(holder, payloads); + RealmRegisteredInfo mRealmRegisteredInfoFrom = RealmRegisteredInfo.getRegistrationInfo(getRealm(), mMessage.structWallet.fromUserId); + RealmRegisteredInfo mRealmRegisteredInfoTo = RealmRegisteredInfo.getRegistrationInfo(getRealm(), mMessage.structWallet.toUserId); + + String persianCalander = HelperCalander.getPersianCalander(mMessage.structWallet.payTime * DateUtils.SECOND_IN_MILLIS); + + if (HelperCalander.isPersianUnicode) { + + holder.fromUserId.setText("" + mRealmRegisteredInfoFrom.getDisplayName()); + holder.toUserId.setText("" + mRealmRegisteredInfoTo.getDisplayName()); + holder.amount.setText("" + mMessage.structWallet.amount); + holder.traceNumber.setText("" + mMessage.structWallet.traceNumber); + holder.invoiceNumber.setText("" + mMessage.structWallet.invoiceNumber); + holder.payTime.setText("" + persianCalander); + + holder.fromUserId_2.setText(R.string.wallet_from); + holder.toUserId_2.setText(R.string.wallet_to); + holder.amount_2.setText(R.string.wallet_amount); + holder.traceNumber_2.setText(R.string.wallet_trace); + holder.invoiceNumber_2.setText(R.string.wallet_invoice); + holder.payTime_2.setText(R.string.wallet_data); + } else { + holder.fromUserId.setText(R.string.wallet_from); + holder.toUserId.setText(R.string.wallet_to); + holder.amount.setText(R.string.wallet_amount); + holder.traceNumber.setText(R.string.wallet_trace); + holder.invoiceNumber.setText(R.string.wallet_invoice); + holder.payTime.setText(R.string.wallet_data); + + holder.fromUserId_2.setText("" + mRealmRegisteredInfoFrom.getDisplayName()); + holder.toUserId_2.setText("" + mRealmRegisteredInfoTo.getDisplayName()); + holder.amount_2.setText("" + mMessage.structWallet.amount); + holder.traceNumber_2.setText("" + mMessage.structWallet.traceNumber); + holder.invoiceNumber_2.setText("" + mMessage.structWallet.invoiceNumber); + holder.payTime_2.setText("" + persianCalander); + } + + if (mMessage.structWallet.description.isEmpty() || mMessage.structWallet.description.equals("")) { + holder.rootDescription.setVisibility(View.GONE); + } else { + holder.description.setText(mMessage.structWallet.description); + } + + + getRealm().close(); + } + + @Override + public ViewHolder getViewHolder(View v) { + return new ViewHolder(v); + } + + protected static class ViewHolder extends RecyclerView.ViewHolder { + + private TextView fromUserId; + private TextView toUserId; + private TextView amount; + private TextView traceNumber; + private TextView invoiceNumber; + private TextView payTime; + private TextView description; + private ViewGroup rootDescription; + + + private TextView fromUserId_2; + private TextView toUserId_2; + private TextView amount_2; + private TextView traceNumber_2; + private TextView invoiceNumber_2; + private TextView payTime_2; + + + protected ReserveSpaceRoundedImageView image; + + public ViewHolder(View view) { + super(view); + + fromUserId = view.findViewById(R.id.fromUserId); + toUserId = view.findViewById(R.id.toUserId); + amount = view.findViewById(R.id.amount); + traceNumber = view.findViewById(R.id.traceNumber); + invoiceNumber = view.findViewById(R.id.invoiceNumber); + payTime = view.findViewById(R.id.payTime); + description = view.findViewById(R.id.description); + rootDescription = view.findViewById(R.id.rootDescription); + + + fromUserId_2 = view.findViewById(R.id.fromUserId_2); + toUserId_2 = view.findViewById(R.id.toUserId_2); + amount_2 = view.findViewById(R.id.amount_2); + traceNumber_2 = view.findViewById(R.id.traceNumber_2); + invoiceNumber_2 = view.findViewById(R.id.invoiceNumber_2); + payTime_2 = view.findViewById(R.id.payTime_2); + + } + } + + private Realm getRealm() { + if (mRealm == null || mRealm.isClosed()) { + mRealm = Realm.getDefaultInstance(); + } + return mRealm; + } +} diff --git a/app/src/main/java/net/iGap/adapter/items/chat/ViewMaker.java b/app/src/main/java/net/iGap/adapter/items/chat/ViewMaker.java index f954e1a..4539c2d 100644 --- a/app/src/main/java/net/iGap/adapter/items/chat/ViewMaker.java +++ b/app/src/main/java/net/iGap/adapter/items/chat/ViewMaker.java @@ -1,14 +1,17 @@ package net.iGap.adapter.items.chat; +import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.graphics.PorterDuff; +import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.support.v4.view.ViewCompat; import android.support.v7.widget.AppCompatImageView; import android.support.v7.widget.LinearLayoutCompat; import android.text.TextUtils; import android.text.method.LinkMovementMethod; +import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.Gravity; import android.view.View; @@ -165,7 +168,7 @@ static View getVoiceItem() { TextView cslv_txt_author = new TextView(G.context); cslv_txt_author.setId(R.id.cslv_txt_author); cslv_txt_author.setText("recorded voice"); - cslv_txt_author.setTextColor(Color.parseColor(G.textTitleTheme)); + cslv_txt_author.setTextColor(Color.parseColor(G.textBubble)); cslv_txt_author.setSingleLine(true); setTextSize(cslv_txt_author, R.dimen.dp14); cslv_txt_author.setMaxLines(2); @@ -383,7 +386,7 @@ static View getLogItem() { text.setGravity(CENTER); text.setText("Log"); if (isDarkTheme) { - text.setTextColor(Color.parseColor(G.textTitleTheme)); + text.setTextColor(Color.parseColor(G.textBubble)); text.setBackgroundResource(R.drawable.recangle_gray_tranceparent_dark); } else { text.setTextColor(Color.parseColor("#4a5d5c")); @@ -506,11 +509,12 @@ static View getViewTime() { txtEditedIndicator.setSingleLine(true); txtEditedIndicator.setText(context.getResources().getString(R.string.edited)); setTextSize(txtEditedIndicator, R.dimen.dp8); - if (G.isDarkTheme) { - txtEditedIndicator.setTextAppearance(context, R.style.text_sub_style_setting_dark); - } else { - txtEditedIndicator.setTextAppearance(context, R.style.ChatMessages_Time); - } +// if (G.isDarkTheme) { +// txtEditedIndicator.setTextAppearance(context, R.style.text_sub_style_setting_dark); +// } else { +// txtEditedIndicator.setTextAppearance(context, R.style.ChatMessages_Time); +// } + txtEditedIndicator.setTextColor(Color.parseColor(G.textBubble)); setTypeFace(txtEditedIndicator); LinearLayout.LayoutParams layout_927 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); @@ -534,7 +538,7 @@ static View getViewTime() { ImageView cslr_txt_tic = new ImageView(context); cslr_txt_tic.setId(R.id.cslr_txt_tic); // cslr_txt_tic.setColorFilter(context.getResources().getColor(R.color.colorOldBlack)); - cslr_txt_tic.setColorFilter(Color.parseColor(G.tintImage), PorterDuff.Mode.SRC_IN); + cslr_txt_tic.setColorFilter(Color.parseColor(G.textBubble), PorterDuff.Mode.SRC_IN); //AppUtils.setImageDrawable(cslr_txt_tic, R.drawable.ic_double_check); LinearLayout.LayoutParams layout_311 = new LinearLayout.LayoutParams(i_Dp(R.dimen.dp16), ViewGroup.LayoutParams.WRAP_CONTENT); layout_311.leftMargin = i_Dp(dp4); @@ -580,7 +584,7 @@ static View getViewSeen() { txt_signature.setText(""); txt_signature.setSingleLine(true); // txt_signature.setFilters(); - txt_signature.setTextColor(context.getResources().getColor(R.color.room_message_gray)); + txt_signature.setTextColor(Color.parseColor(G.textBubble)); txt_signature.setTextAppearance(context, R.style.ChatMessages_Time); LinearLayout.LayoutParams layout_266 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, i_Dp(R.dimen.dp18)); txt_signature.setLayoutParams(layout_266); @@ -596,7 +600,7 @@ static View getViewSeen() { setTypeFace(txt_views_label); txt_views_label.setPadding(0, dpToPixel(2), 0, 0); - txt_views_label.setTextColor(context.getResources().getColor(R.color.room_message_gray)); + txt_views_label.setTextColor(Color.parseColor(G.textBubble)); LinearLayout.LayoutParams layout_959 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, i_Dp(R.dimen.dp16)); txt_views_label.setLayoutParams(layout_959); lyt_see.addView(txt_views_label); @@ -604,7 +608,7 @@ static View getViewSeen() { MaterialDesignTextView img_eye = new MaterialDesignTextView(context); img_eye.setId(R.id.img_eye); img_eye.setText(context.getResources().getString(R.string.md_visibility)); - img_eye.setTextColor(context.getResources().getColor(R.color.gray_6c)); + img_eye.setTextColor(Color.parseColor(G.textBubble)); setTextSize(img_eye, R.dimen.dp12); // img_eye.setPadding(0, dpToPixel(2), 0, 0); img_eye.setSingleLine(true); @@ -729,7 +733,7 @@ static View getViewForward() { cslr_ll_forward.setLayoutParams(layout_687); View View_997 = new View(context); - View_997.setBackgroundColor(Color.parseColor(G.textTitleTheme)); + View_997.setBackgroundColor(Color.parseColor(G.textBubble)); LinearLayout.LayoutParams layout_547 = new LinearLayout.LayoutParams(dpToPixel(2), ViewGroup.LayoutParams.MATCH_PARENT); layout_547.rightMargin = dpToPixel(3); View_997.setLayoutParams(layout_547); @@ -739,7 +743,7 @@ static View getViewForward() { TextView cslr_txt_prefix_forward = new TextView(context); cslr_txt_prefix_forward.setId(R.id.cslr_txt_prefix_forward); cslr_txt_prefix_forward.setText(context.getResources().getString(R.string.forwarded_from)); - cslr_txt_prefix_forward.setTextColor(Color.parseColor(G.textTitleTheme)); + cslr_txt_prefix_forward.setTextColor(Color.parseColor(G.textBubble)); setTextSize(cslr_txt_prefix_forward, R.dimen.dp12); cslr_txt_prefix_forward.setSingleLine(true); cslr_txt_prefix_forward.setTypeface(G.typeface_IRANSansMobile_Bold); @@ -753,7 +757,7 @@ static View getViewForward() { cslr_txt_forward_from.setId(R.id.cslr_txt_forward_from); cslr_txt_forward_from.setMinimumWidth(i_Dp(R.dimen.dp100)); cslr_txt_forward_from.setMaxWidth(i_Dp(R.dimen.dp140)); - cslr_txt_forward_from.setTextColor(Color.parseColor(G.textTitleTheme)); + cslr_txt_forward_from.setTextColor(Color.parseColor(G.textBubble)); setTextSize(cslr_txt_forward_from, R.dimen.dp12); cslr_txt_forward_from.setSingleLine(true); cslr_txt_forward_from.setTypeface(G.typeface_IRANSansMobile_Bold); @@ -779,11 +783,12 @@ static View getViewVote() { LinearLayout lyt_vote_sub = new LinearLayout(context); lyt_vote_sub.setOrientation(VERTICAL); lyt_vote_sub.setId(R.id.lyt_vote_sub); - if (G.isDarkTheme) { - lyt_vote_sub.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round_vote_dark)); - } else { - lyt_vote_sub.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round)); - } + + lyt_vote_sub.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round)); + + + GradientDrawable circleDarkColor = (GradientDrawable) lyt_vote_sub.getBackground(); + circleDarkColor.setColor(Color.parseColor(G.appBarColor)); LinearLayout.LayoutParams layout_35644 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layout_35644.leftMargin = i_Dp(R.dimen.dp2); @@ -821,11 +826,12 @@ static View getViewVote() { lyt_vote_sub.addView(lyt_vote_up); LinearLayout lyt_vote_down = new LinearLayout(context); - if (G.isDarkTheme) { - lyt_vote_down.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round_vote_dark)); - } else { - lyt_vote_down.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round)); - } + + lyt_vote_down.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round)); + + GradientDrawable circleDarkColor_2 = (GradientDrawable) lyt_vote_down.getBackground(); + circleDarkColor_2.setColor(Color.parseColor(G.appBarColor)); + lyt_vote_down.setId(R.id.lyt_vote_down); lyt_vote_down.setPadding(0, i_Dp(R.dimen.dp6), 0, 0); lyt_vote_down.setGravity(CENTER); @@ -865,11 +871,12 @@ private static View getForwardButton() { lyt_vote_forward.setGravity(CENTER); lyt_vote_forward.setOrientation(VERTICAL); - if (G.isDarkTheme) { - lyt_vote_forward.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.circle_white_dark)); - } else { - lyt_vote_forward.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.circle_white)); - } + + lyt_vote_forward.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.circle_white)); + + GradientDrawable circleDarkColor = (GradientDrawable) lyt_vote_forward.getBackground(); + circleDarkColor.setColor(Color.parseColor(G.appBarColor)); + LinearLayout.LayoutParams layout_799_f = new LinearLayout.LayoutParams(i_Dp(R.dimen.dp32), i_Dp(R.dimen.dp32)); layout_799_f.topMargin = i_Dp(R.dimen.dp8); layout_799_f.bottomMargin = i_Dp(R.dimen.dp16); @@ -959,7 +966,7 @@ static View getAudioItem() { fileSize.setSingleLine(true); fileSize.setText("3.2 mb"); fileSize.setAllCaps(TRUE); - fileSize.setTextColor(Color.parseColor(G.textTitleTheme)); + fileSize.setTextColor(Color.parseColor(G.textChatMusic)); setTextSize(fileSize, R.dimen.dp12); setTypeFace(fileSize); LinearLayout.LayoutParams layout_996 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); @@ -980,7 +987,7 @@ static View getAudioItem() { fileName.setTextAppearance(context, android.R.style.TextAppearance_Medium); fileName.setMaxWidth((int) G.context.getResources().getDimension(R.dimen.dp160)); fileName.setText("file_name.ext"); - fileName.setTextColor(Color.parseColor(G.textTitleTheme)); + fileName.setTextColor(Color.parseColor(G.textChatMusic)); setTextSize(fileName, R.dimen.dp14); fileName.setTypeface(G.typeface_IRANSansMobile_Bold); LinearLayout.LayoutParams layout_298 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); @@ -993,7 +1000,7 @@ static View getAudioItem() { songArtist.setSingleLine(true); songArtist.setText("Artist"); setTypeFace(songArtist); - songArtist.setTextColor(Color.parseColor(G.textTitleTheme)); + songArtist.setTextColor(Color.parseColor(G.textChatMusic)); LinearLayout.LayoutParams layout_757 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); songArtist.setLayoutParams(layout_757); linearLayout_222.addView(songArtist); @@ -1116,7 +1123,7 @@ static View getContactItem() { LinearLayout.LayoutParams layoutParamsName = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); name.setId(R.id.name); name.setTextAppearance(context, android.R.style.TextAppearance_Medium); - name.setTextColor(Color.parseColor(G.textTitleTheme)); + name.setTextColor(Color.parseColor(G.textBubble)); name.setText("Contact Name"); setTextSize(name, R.dimen.dp14); setTypeFace(name); @@ -1129,7 +1136,7 @@ static View getContactItem() { number.setTextAppearance(context, android.R.style.TextAppearance_Small); setTypeFace(number); - number.setTextColor(Color.parseColor(G.textTitleTheme)); + number.setTextColor(Color.parseColor(G.textBubble)); number.setText("Contact Number"); number.setLayoutParams(layoutParamsNumber); @@ -1207,7 +1214,7 @@ static View getFileItem() { songArtist.setMaxWidth((int) G.context.getResources().getDimension(R.dimen.dp180)); songArtist.setText("file_name.ext"); - songArtist.setTextColor(Color.parseColor(G.textTitleTheme)); + songArtist.setTextColor(Color.parseColor(G.textBubble)); setTextSize(songArtist, R.dimen.dp14); songArtist.setTypeface(G.typeface_IRANSansMobile_Bold, BOLD); LinearLayout.LayoutParams layout_1000 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); @@ -1219,7 +1226,7 @@ static View getFileItem() { fileSize.setSingleLine(true); fileSize.setText("3.2 mb"); fileSize.setAllCaps(TRUE); - fileSize.setTextColor(Color.parseColor(G.textTitleTheme)); + fileSize.setTextColor(Color.parseColor(G.textBubble)); setTextSize(fileSize, R.dimen.dp10); setTypeFace(fileSize); LinearLayout.LayoutParams layout_958 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); @@ -1298,11 +1305,11 @@ static View makeTextViewMessage(int maxsize, boolean hasEmoji, boolean hasLink) if (hasEmoji) { EmojiTextViewE emojiTextViewE = new EmojiTextViewE(context); emojiTextViewE.setLayoutParams(new LinearLayoutCompat.LayoutParams(LinearLayoutCompat.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); - if (G.isDarkTheme) { - emojiTextViewE.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - emojiTextViewE.setTextColor(Color.parseColor("#333333")); - } +// if (G.isDarkTheme) { + emojiTextViewE.setTextColor(Color.parseColor(G.textBubble)); +// } else { +// emojiTextViewE.setTextColor(Color.parseColor("#333333")); +// } emojiTextViewE.setId(R.id.messageSenderTextMessage); emojiTextViewE.setPadding(10, 4, 10, 4); @@ -1325,11 +1332,11 @@ static View makeTextViewMessage(int maxsize, boolean hasEmoji, boolean hasLink) } else { TextView textView = new TextView(context); textView.setLayoutParams(new LinearLayoutCompat.LayoutParams(LinearLayoutCompat.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); - if (G.isDarkTheme) { - textView.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - textView.setTextColor(Color.parseColor("#333333")); - } +// if (G.isDarkTheme) { + textView.setTextColor(Color.parseColor(G.textBubble)); +// } else { +// textView.setTextColor(Color.parseColor("#333333")); +// } textView.setId(R.id.messageSenderTextMessage); textView.setPadding(10, 0, 10, 0); @@ -1354,11 +1361,11 @@ static View makeHeaderTextView(String text) { EmojiTextViewE textView = new EmojiTextViewE(context); - if (G.isDarkTheme) { - textView.setTextColor(Color.BLACK); - } else { - textView.setTextColor(Color.parseColor(G.textTitleTheme)); - } +// if (G.isDarkTheme) { +// textView.setTextColor(Color.BLACK); +// } else { + textView.setTextColor(Color.parseColor(G.textBubble)); +// } textView.setBackgroundResource(R.drawable.rect_radios_top_gray); textView.setId(R.id.messageSenderName); @@ -1420,7 +1427,7 @@ private static View getProgressBar(int sizeSrc) { /** * ***************** Common Methods ***************** */ - private static int dpToPixel(int dp) { + public static int dpToPixel(int dp) { Resources r = context.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); return px; @@ -1428,6 +1435,14 @@ private static int dpToPixel(int dp) { // (2/getApplicationContext().getResources().getDisplayMetrics().density) } + + public static float pixelsToDp(float px, Context context) { + Resources resources = context.getResources(); + DisplayMetrics metrics = resources.getDisplayMetrics(); + float dp = px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); + return dp; + } + public static int i_Dp(int dpSrc) { return (int) context.getResources().getDimension(dpSrc); @@ -1701,7 +1716,7 @@ public static View getViewItemRoom() { MaterialDesignTextView cs_txt_mute = new MaterialDesignTextView(G.context); cs_txt_mute.setId(R.id.cs_txt_mute); cs_txt_mute.setText(G.fragmentActivity.getResources().getString(R.string.md_muted)); - cs_txt_mute.setTextColor(G.context.getResources().getColor(R.color.grayNew)); + cs_txt_mute.setTextColor(Color.parseColor(G.textTitleTheme)); setTextSize(cs_txt_mute, R.dimen.dp13); LinearLayout.LayoutParams layout_152s = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layout_152s.leftMargin = i_Dp(R.dimen.dp4); @@ -1728,7 +1743,7 @@ public static View getViewItemRoom() { cs_txt_contact_time.setId(R.id.cs_txt_contact_time); cs_txt_contact_time.setSingleLine(true); cs_txt_contact_time.setText("time"); - cs_txt_contact_time.setTextColor(G.context.getResources().getColor(R.color.gray)); + cs_txt_contact_time.setTextColor(Color.parseColor(G.textTitleTheme)); setTextSize(cs_txt_contact_time, R.dimen.dp12); LinearLayout.LayoutParams layout_574 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layout_574.gravity = Gravity.CENTER; @@ -1758,7 +1773,7 @@ public static View getViewItemRoom() { cs_txt_pinned_message.setId(R.id.cs_txt_pinned_message); cs_txt_pinned_message.setGravity(CENTER); cs_txt_pinned_message.setText(G.fragmentActivity.getResources().getString(R.string.md_circlePin)); - cs_txt_pinned_message.setTextColor(Color.parseColor(G.textSubTheme)); + cs_txt_pinned_message.setTextColor(Color.parseColor(G.textTitleTheme)); cs_txt_pinned_message.setTextSize(i_Dp(R.dimen.dp20)); setTextSize(cs_txt_pinned_message, R.dimen.dp20); LinearLayout.LayoutParams layout_175 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); @@ -1774,7 +1789,7 @@ public static View getViewItemRoom() { linearLayout_849.addView(linearLayout_938); View textView_186 = new View(G.context); - textView_186.setBackgroundColor(Color.parseColor("#52afafaf")); + textView_186.setBackgroundColor(Color.parseColor(G.lineBorder)); LinearLayout.LayoutParams layout_552 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); textView_186.setLayoutParams(layout_552); linearLayout_849.addView(textView_186); diff --git a/app/src/main/java/net/iGap/adapter/items/chat/VoiceItem.java b/app/src/main/java/net/iGap/adapter/items/chat/VoiceItem.java index 3b6ad31..d745505 100644 --- a/app/src/main/java/net/iGap/adapter/items/chat/VoiceItem.java +++ b/app/src/main/java/net/iGap/adapter/items/chat/VoiceItem.java @@ -218,7 +218,11 @@ public boolean onTouch(View v, MotionEvent event) { MusicPlayer.onCompleteChat = holder.complete; holder.musicSeekbar.setProgress(MusicPlayer.musicProgress); - holder.txt_Timer.setText(MusicPlayer.strTimer + "/" + MusicPlayer.musicTime); + + if (MusicPlayer.musicProgress > 0) { + holder.txt_Timer.setText(MusicPlayer.strTimer + "/" + MusicPlayer.musicTime); + } + holder.mTimeMusic = MusicPlayer.musicTime; diff --git a/app/src/main/java/net/iGap/eventbus/DialogMaker.java b/app/src/main/java/net/iGap/eventbus/DialogMaker.java new file mode 100644 index 0000000..0b7338d --- /dev/null +++ b/app/src/main/java/net/iGap/eventbus/DialogMaker.java @@ -0,0 +1,53 @@ +package net.iGap.eventbus; + +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.graphics.drawable.ColorDrawable; +import android.support.annotation.NonNull; +import android.view.KeyEvent; +import android.view.Window; + +import net.iGap.R; + + +public class DialogMaker { + + private static Dialog dialog; + + @NonNull + public static DialogMaker makeDialog(Context context) { + DialogMaker dialogMaker = new DialogMaker(); + dialog = new Dialog(context); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setContentView(R.layout.gif_dialog); + dialog.setCanceledOnTouchOutside(false); + dialog.setCancelable(false); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); + + dialog.setOnKeyListener(new Dialog.OnKeyListener() { + @Override + public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) { + // TODO Auto-generated method stub + if (keyCode == KeyEvent.KEYCODE_BACK) { + dialog.dismiss(); + } + return true; + } + }); + + return dialogMaker; + } + + public static void disMissDialog() { + if (dialog != null) { + dialog.dismiss(); + } + } + + public void showDialog() { + dialog.show(); + } + + +} diff --git a/app/src/main/java/net/iGap/eventbus/ErrorHandler.java b/app/src/main/java/net/iGap/eventbus/ErrorHandler.java new file mode 100644 index 0000000..5b611a1 --- /dev/null +++ b/app/src/main/java/net/iGap/eventbus/ErrorHandler.java @@ -0,0 +1,9 @@ +package net.iGap.eventbus; + +/** + * Created by keyvan on 7/14/17. + */ + +public interface ErrorHandler { + void onFailure(Throwable e); +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/eventbus/EventListener.java b/app/src/main/java/net/iGap/eventbus/EventListener.java new file mode 100644 index 0000000..7aaf730 --- /dev/null +++ b/app/src/main/java/net/iGap/eventbus/EventListener.java @@ -0,0 +1,11 @@ +package net.iGap.eventbus; + +/** + * Created by keyvan on 7/14/17. + */ + +public interface EventListener { + void receivedMessage(int id, Object... message); + + +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/eventbus/EventManager.java b/app/src/main/java/net/iGap/eventbus/EventManager.java new file mode 100644 index 0000000..8799014 --- /dev/null +++ b/app/src/main/java/net/iGap/eventbus/EventManager.java @@ -0,0 +1,201 @@ +package net.iGap.eventbus; + +import android.support.annotation.Nullable; +import android.util.Log; +import android.util.SparseArray; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.locks.ReentrantLock; + + +/** + * Created by keyvan on 3/14/16. + */ +public class EventManager { + + /** + * READ ME : + * this class used for notifying part of application to another part that not related to each other + * for using this class you need to use instance method. + * if your event number is exists just use it (I will tell in continue how to use), else declare your event number + * event number MUST NOT equal with other event number, for this purpose use '++' to increment last number. + *

+ * HOW TO USE: + * in onCreate() or onStart() ( It's related to your usage ) use following function : + * {@link EventManager#getInstance()#addEventListener(int, EventListener)} + * int is your event num and EventListener can be `this` so your activity must be implement or new instance of EventListener + * {@link EventListener}. + * then in onDestroy() or onPause() use {@link EventManager#getInstance()#removeEventListener(int, EventListener)} + * to optimize eventManager and prevent from crash. + * PS: if you remove your listener with above code your component not listen on event anymore. + *

+ * after getting event onReceived will be called in eventManager thread, + * if you want heavy process in {@link EventListener#receivedMessage(int, Object...)} use your thread + */ + + + public static final int ON_ACCESS_TOKEN_RECIVE = 1; + public static final int ON_INIT_PAY = 2; + public static final int ON_INIT_PAY_ERROR = 4; + public static final int ON_PAYMENT_RESULT_RECIEVED = 3; + + + private static EventManager eventListenerInstance; + + private ErrorHandler errorHandler; + private ExecutorService threadPool; + private SparseArray> eventListenerMap; + private ReentrantLock eventLock = new ReentrantLock(true); + + + private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); + private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1; + private static final int DEFAULT_POOL_SIZE = 2; + + + private EventManager(int threadPoolSize, boolean loggingInDebug, @Nullable ErrorHandler errorHandler) { + eventListenerMap = new SparseArray<>(); + + this.errorHandler = errorHandler; + + if (threadPoolSize > MAXIMUM_POOL_SIZE) { + threadPoolSize = MAXIMUM_POOL_SIZE; + } + + threadPool = Executors.newFixedThreadPool(threadPoolSize); + } + + + public static EventManager getInstance() { + if (eventListenerInstance == null) { + eventListenerInstance = new EventManager(DEFAULT_POOL_SIZE, false, null); + } + + return eventListenerInstance; + } + + public void addEventListener(final int eventNum, final EventListener listener) { + + if (listener == null) { + return; + } + + + threadPool.submit(new Runnable() { + @Override + public void run() { + eventLock.lock(); + try { + List objects = eventListenerMap.get(eventNum); + if (objects == null) { + objects = new ArrayList<>(); + } + + if (objects.contains(listener)) { + return; + } + + objects.add(listener); + eventListenerMap.put(eventNum, objects); + + Logger.printLog("addEventListener with eventNum = " + eventNum + ".\nNow " + objects.size() + " listener listen on this eventNum", null); + } finally { + eventLock.unlock(); + } + } + }); + } + + public void removeEventListener(final int eventNum, final EventListener listener) { + + final List eventListeners = eventListenerMap.get(eventNum); + if (eventListeners == null || eventListeners.size() == 0) { + Logger.printLog("eventListeners is null, there is no event with this eventNum = " + eventNum, null); + return; + } + + threadPool.submit(new Runnable() { + @Override + public void run() { + eventLock.lock(); + try { + eventListeners.remove(listener); + Logger.printLog("removeEvent for this eventNum = " + eventNum + ".\nNow " + eventListeners.size() + " listener listen on this eventNum", null); + } finally { + eventLock.unlock(); + } + + } + }); + } + + public void postEvent(final int eventNum, final Object... message) { + + final List eventListeners = eventListenerMap.get(eventNum); + if (eventListeners == null || eventListeners.size() == 0) { + Logger.printLog("there is no listener for this eventNum = " + eventNum, null); + return; + } + + Logger.printLog("postEvent for this eventNum = " + eventNum, null); + + threadPool.submit(new Runnable() { + @Override + public void run() { + + eventLock.lock(); + try { + for (EventListener listener : eventListeners) { + try { + listener.receivedMessage(eventNum, message); + } catch (Exception e) { + Logger.printLog("error happened in receiveMessage", e); + if (errorHandler != null) { + errorHandler.onFailure(e); + } + } + } + } finally { + eventLock.unlock(); + } + } + }); + } + + + public static class Builder { + + + private int threadPoolSize = DEFAULT_POOL_SIZE; + private ErrorHandler errorHandler; + private boolean loggingInDebug = false; + + public Builder setThreadPoolSize(int threadPoolSize) { + this.threadPoolSize = threadPoolSize; + return this; + } + + public Builder setErrorHandler(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + return this; + } + + public Builder enableLoggingInDebug() { + this.loggingInDebug = true; + return this; + } + + public void build() { + + // only one object can build. you can't init twice. + if (eventListenerInstance != null) { + return; + } + + eventListenerInstance = new EventManager(threadPoolSize, loggingInDebug, errorHandler); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/eventbus/Logger.java b/app/src/main/java/net/iGap/eventbus/Logger.java new file mode 100644 index 0000000..e1ec925 --- /dev/null +++ b/app/src/main/java/net/iGap/eventbus/Logger.java @@ -0,0 +1,21 @@ +package net.iGap.eventbus; + + +/** + * Created by keyvan on 7/14/17. + */ + +public class Logger { + + private static boolean loggingInDebug = false; + + static void printLog(String message, Exception e) { +// if (!BuildConfig.DEBUG || !loggingInDebug) { +// return; +// } + +// APP.gLogger.d(message); +// APP.gLogger.d(e); + + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/eventbus/OnPaymentInit.java b/app/src/main/java/net/iGap/eventbus/OnPaymentInit.java new file mode 100644 index 0000000..7b6ffa2 --- /dev/null +++ b/app/src/main/java/net/iGap/eventbus/OnPaymentInit.java @@ -0,0 +1,18 @@ +package net.iGap.eventbus; + +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ +public interface OnPaymentInit { + + void successPaymentInit(); + + void errorPaymentInit(); + +} diff --git a/app/src/main/java/net/iGap/eventbus/PaymentFragment.java b/app/src/main/java/net/iGap/eventbus/PaymentFragment.java new file mode 100644 index 0000000..fc9fbc7 --- /dev/null +++ b/app/src/main/java/net/iGap/eventbus/PaymentFragment.java @@ -0,0 +1,701 @@ +package net.iGap.eventbus; + + +import android.content.Intent; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.os.Bundle; +import android.support.design.widget.TextInputLayout; +import android.support.v4.app.DialogFragment; +import android.text.Editable; +import android.text.InputType; +import android.text.TextUtils; +import android.text.TextWatcher; +import android.text.method.PasswordTransformationMethod; +import android.util.Log; +import android.util.TypedValue; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Toast; + +import com.afollestad.materialdialogs.DialogAction; +import com.afollestad.materialdialogs.MaterialDialog; +import com.google.gson.Gson; +import com.google.zxing.integration.android.IntentIntegrator; +import com.google.zxing.integration.android.IntentResult; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.databinding.PaymentDialogBinding; +import net.iGap.fragments.BaseFragment; +import net.iGap.helper.HelperError; +import net.iGap.helper.HelperFragment; +import net.iGap.interfaces.OnUserProfileSetNickNameResponse; +import net.iGap.module.EmojiEditTextE; +import net.iGap.proto.ProtoGlobal; +import net.iGap.proto.ProtoWalletPaymentInit; +import net.iGap.realm.RealmRoom; +import net.iGap.request.RequestUserProfileSetNickname; +import net.iGap.request.RequestUserVerifyNewDevice; +import net.iGap.request.RequestWalletPaymentInit; +import net.iGap.webservice.APIService; +import net.iGap.webservice.ApiUtils; +import net.iGap.webservice.Post; + +import org.paygear.wallet.RaadApp; +import org.paygear.wallet.WalletActivity; +import org.paygear.wallet.fragment.CardFragment; +import org.paygear.wallet.fragment.PaymentResultDialog; +import org.paygear.wallet.fragment.SetCardPinFragment; +import org.paygear.wallet.model.Card; +import org.paygear.wallet.model.Payment; +import org.paygear.wallet.model.PaymentAuth; +import org.paygear.wallet.model.PaymentResult; +import org.paygear.wallet.web.Web; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.logging.ErrorManager; + +import ir.radsense.raadcore.app.AlertDialog; +import ir.radsense.raadcore.model.Auth; +import ir.radsense.raadcore.web.PostRequest; +import okhttp3.MediaType; +import okhttp3.RequestBody; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +import static android.app.Activity.RESULT_OK; +import static net.iGap.G.context; +import static net.iGap.G.fragmentActivity; +import static net.iGap.G.smsNumbers; +import static org.paygear.wallet.utils.RSAUtils.getRSA; + +public class PaymentFragment extends BaseFragment implements EventListener { + + private Drawable userPicture; + private String userName; + PaymentDialogBinding paymentDialogBinding; + Card selectedCard = null; + long userId = 0; + final String[] mPrice = {""}; + public static final int requestCodePaymentCharge = 1; + public static final int requestCodePaymentBill = 2; + public static final int requestCodeQrCode = 200; + public static final int requestCodeBarcode = 201; + MaterialDialog progressDialog; + private APIService mAPIService; + + public PaymentFragment() { + // Required empty public constructor + } + + + public static PaymentFragment newInstance(Long userId, Drawable userpicture, String userName) { + PaymentFragment fragment = new PaymentFragment(); + fragment.userName = userName; + fragment.userPicture = userpicture; + fragment.userId = userId; + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.payment_dialog, container, false); + paymentDialogBinding = PaymentDialogBinding.bind(view); + if (userPicture != null) + paymentDialogBinding.imageView.setImageDrawable(userPicture); + if (userName != null) + paymentDialogBinding.subtitle.setText(userName); + if (G.selectedCard != null) { + paymentDialogBinding.amountCard.setText(getResources().getString(R.string.wallet_Your_credit) + " " + String.valueOf(G.cardamount) + " " + getResources().getString(R.string.wallet_Reial)); + } else { + paymentDialogBinding.amountCard.setVisibility(View.GONE); + } + paymentDialogBinding.payButton.getBackground().setColorFilter(new PorterDuffColorFilter(Color.parseColor(WalletActivity.primaryColor), PorterDuff.Mode.SRC_IN)); + paymentDialogBinding.dialogHeader.getBackground().setColorFilter(new PorterDuffColorFilter(Color.parseColor(WalletActivity.primaryColor), PorterDuff.Mode.SRC_IN)); + + paymentDialogBinding.outside.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + G.fragmentActivity.onBackPressed(); + } + }); + paymentDialogBinding.amount.addTextChangedListener(new TextWatcher() { + boolean isSettingText; + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + mPrice[0] = s.toString().replaceAll(",", ""); + } + + @Override + public void afterTextChanged(Editable editable) { + if (isSettingText) return; + isSettingText = true; + String s = null; + try { + s = String.format(Locale.US, "%,d", Long.parseLong(mPrice[0])); + } catch (NumberFormatException e) { + } + paymentDialogBinding.amount.setText(s); + paymentDialogBinding.amount.setSelection(paymentDialogBinding.amount.length()); + isSettingText = false; + } + }); + + paymentDialogBinding.payButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mPrice[0] != null && !mPrice[0].isEmpty()) { + paymentDialogBinding.payButton.setEnabled(false); + showProgress(); + new RequestWalletPaymentInit().walletPaymentInit(ProtoGlobal.Language.FA_IR, Auth.getCurrentAuth().accessToken, userId, Long.parseLong(mPrice[0]), paymentDialogBinding.edtDescription.getText().toString()); + + } + + } + }); + EventManager.getInstance().addEventListener(EventManager.ON_INIT_PAY, this); + return view; + } + + @Override + public void receivedMessage(int id, Object... message) { + + G.handler.post(new Runnable() { + @Override + public void run() { + paymentDialogBinding.payButton.setEnabled(true); + } + }); + + switch (id) { + case EventManager.ON_INIT_PAY: + if (message == null) { + G.handler.post(new Runnable() { + @Override + public void run() { + if (progressDialog != null) progressDialog.dismiss(); + HelperError.showSnackMessage(getResources().getString(R.string.PayGear_unavailable), false); + } + }); + return; + } + final ProtoWalletPaymentInit.WalletPaymentInitResponse.Builder initPayResponse = (ProtoWalletPaymentInit.WalletPaymentInitResponse.Builder) message[0]; + if (initPayResponse != null) { + new android.os.Handler(getContext().getMainLooper()).post(new Runnable() { + @Override + public void run() { + Web.getInstance().getWebService().getCredit(Auth.getCurrentAuth().getId()).enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + if (progressDialog != null) progressDialog.dismiss(); + + if (!HelperFragment.isFragmentVisible("PaymentFragment")) + return; + if (response.body() != null) { + selectedCard = null; + if (response.body().size() > 0) + selectedCard = response.body().get(0); + if (selectedCard != null) { + if (selectedCard.cashOutBalance >= Long.parseLong(mPrice[0])) { + if (!selectedCard.isProtected) { + if (progressDialog != null) + progressDialog.dismiss(); + + setNewPassword(); + + } else { + + if (progressDialog != null) + progressDialog.dismiss(); + PaymentAuth paymentAuth = new PaymentAuth(); + paymentAuth.publicKey = initPayResponse.getPublicKey(); + paymentAuth.token = initPayResponse.getToken(); +// showPinConfirm(paymentAuth); + setConfirmPassword(paymentAuth); + + + } + } else { + if (progressDialog != null) + progressDialog.dismiss(); + + Payment payment = new Payment(); + PaymentAuth paymentAuth = new PaymentAuth(); + paymentAuth.token = initPayResponse.getToken(); + paymentAuth.publicKey = initPayResponse.getPublicKey(); + payment.account = null; + payment.paymentAuth = paymentAuth; + payment.isCredit = false; + payment.orderId = null; + payment.price = Long.parseLong(mPrice[0]); + Intent intent = new Intent(context, WalletActivity.class); + intent.putExtra("Language", "fa"); + intent.putExtra("Mobile", "0" + String.valueOf(G.userId)); + intent.putExtra("IsP2P", true); + intent.putExtra("Payment", payment); + intent.putExtra("PrimaryColor", G.appBarColor); + intent.putExtra("DarkPrimaryColor", G.appBarColor); + intent.putExtra("AccentColor", G.appBarColor); + intent.putExtra(WalletActivity.PROGRESSBAR, G.progressColor); + intent.putExtra(WalletActivity.LINE_BORDER, G.lineBorder); + intent.putExtra(WalletActivity.BACKGROUND, G.backgroundTheme); + intent.putExtra(WalletActivity.BACKGROUND_2, G.backgroundTheme_2); + intent.putExtra(WalletActivity.TEXT_TITLE, G.textTitleTheme); + intent.putExtra(WalletActivity.TEXT_SUB_TITLE, G.textSubTheme); + startActivityForResult(intent, 66); + G.currentActivity.onBackPressed(); + } + + } + } + } + + @Override + public void onFailure(Call> call, Throwable t) { + if (paymentDialogBinding.payButton != null) + paymentDialogBinding.payButton.setEnabled(true); + if (progressDialog != null) progressDialog.dismiss(); + + HelperError.showSnackMessage(getResources().getString(R.string.PayGear_unavailable), false); + } + }); + + } + }); + } else { + if (progressDialog != null) progressDialog.dismiss(); + HelperError.showSnackMessage(getResources().getString(R.string.PayGear_unavailable), false); + } + case EventManager.ON_PAYMENT_RESULT_RECIEVED: + + if (progressDialog != null) progressDialog.dismiss(); + int response = (int) message[0]; + switch (response) { + case socketMessages.PaymentResultRecievedSuccess: + new android.os.Handler(getContext().getMainLooper()).post(new Runnable() { + @Override + public void run() { + fragmentActivity.onBackPressed(); + + HelperError.showSnackMessage(getResources().getString(R.string.result_4), false); + } + }); + + break; + + case socketMessages.PaymentResultRecievedFailed: + new android.os.Handler(getContext().getMainLooper()).post(new Runnable() { + @Override + public void run() { + fragmentActivity.onBackPressed(); + HelperError.showSnackMessage(getResources().getString(R.string.not_success_2), false); + } + }); + break; + + case socketMessages.PaymentResultNotRecieved: + new android.os.Handler(getContext().getMainLooper()).post(new Runnable() { + @Override + public void run() { + fragmentActivity.onBackPressed(); + HelperError.showSnackMessage(getResources().getString(R.string.result_3), false); + + } + }); + break; + } + + case EventManager.ON_INIT_PAY_ERROR: + if (progressDialog != null) progressDialog.dismiss(); + break; + } + // backthread + + } + + private void startPay(final PaymentAuth paymentAuth, String pin) { + + String cardDataRSA = getCardDataRSA(paymentAuth, selectedCard, pin, null); + Map finalInfoMap = new HashMap<>(); + finalInfoMap.put("token", paymentAuth.token); + finalInfoMap.put("card_info", cardDataRSA); +// DialogMaker.makeDialog(getContext()).showDialog(); + showProgress(); + Web.getInstance().getWebService().pay(PostRequest.getRequestBody(finalInfoMap)).enqueue(new Callback() { + @Override + public void onResponse(Call call, final Response response) { + + Boolean success = Web.checkResponse(PaymentFragment.this, call, response); + if (success == null) + return; + + if (progressDialog != null) progressDialog.dismiss(); +// DialogMaker.disMissDialog(); + if (response.errorBody() == null && response.body() != null) { + PaymentResult paymentResult = response.body(); + final PaymentResultDialog dialog = PaymentResultDialog.newInstance(paymentResult); + dialog.setListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + RaadApp.cards = null; + dialog.dismiss(); + fragmentActivity.onBackPressed(); + sendPost(response.body().callbackUrl, paymentAuth.token); + G.cardamount -= response.body().amount; + } + } , G.appBarColor ); + dialog.show(getActivity().getSupportFragmentManager(), "PaymentSuccessDialog"); + } + } + + @Override + public void onFailure(Call call, Throwable t) { +// DialogMaker.disMissDialog(); + + if (progressDialog != null) progressDialog.dismiss(); + HelperError.showSnackMessage(getResources().getString(R.string.wallet_error_server), false); + + } + }); + + } + + public static String getCardDataRSA(PaymentAuth paymentAuth, Card mCard, String pin2, String cvv2) { + Map map = new HashMap(); + map.put("t", System.currentTimeMillis()); + map.put("c", mCard.token); + map.put("bc", mCard.bankCode); + map.put("type", mCard.type); + if (!TextUtils.isEmpty(cvv2)) { + map.put("cv", cvv2); + } + + if (pin2 != null) { + map.put("p2", pin2); + } + + Gson gson = new Gson(); + String cardInfoJson = gson.toJson(map); + String publicKey; + if (paymentAuth != null) { + publicKey = paymentAuth.publicKey; + } else { + publicKey = Auth.getCurrentAuth().getPublicKey(); + } + + return getRSA(publicKey, cardInfoJson); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + switch (requestCode) { + + case 66: + if (resultCode == RESULT_OK) { + PaymentResult paymentResult = (PaymentResult) data.getSerializableExtra("result"); + if (paymentResult != null) { + HelperError.showSnackMessage(getResources().getString(R.string.trace_number) + String.valueOf(paymentResult.traceNumber) + getResources().getString(R.string.amount_2) + String.valueOf(paymentResult.amount), false); + EventManager.getInstance().postEvent(EventManager.ON_PAYMENT_RESULT_RECIEVED, socketMessages.PaymentResultRecievedSuccess); + } else { + HelperError.showSnackMessage(getResources().getString(R.string.not_success), false); + EventManager.getInstance().postEvent(EventManager.ON_PAYMENT_RESULT_RECIEVED, socketMessages.PaymentResultRecievedFailed); + + } + } else { + + HelperError.showSnackMessage(getResources().getString(R.string.payment_canceled), false); + EventManager.getInstance().postEvent(EventManager.ON_PAYMENT_RESULT_RECIEVED, socketMessages.PaymentResultNotRecieved); + } + break; + } + + } + + public void setNewPassword() { + final LinearLayout layoutNickname = new LinearLayout(G.fragmentActivity); + layoutNickname.setOrientation(LinearLayout.VERTICAL); + + final View viewNewPassword = new View(G.fragmentActivity); + viewNewPassword.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); + LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); + + TextInputLayout inputNewPassWord = new TextInputLayout(G.fragmentActivity); + final EditText newPassWord = new EditText(G.fragmentActivity); + newPassWord.setHint(G.fragmentActivity.getResources().getString(R.string.please_enter_your_password)); + newPassWord.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI); + newPassWord.setTypeface(G.typeface_IRANSansMobile); + newPassWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, G.context.getResources().getDimension(R.dimen.dp14)); + newPassWord.setTextColor(G.context.getResources().getColor(R.color.text_edit_text)); + newPassWord.setHintTextColor(G.context.getResources().getColor(R.color.hint_edit_text)); + newPassWord.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); + newPassWord.setTransformationMethod(PasswordTransformationMethod.getInstance()); + newPassWord.setPadding(0, 8, 0, 8); + newPassWord.setMaxLines(1); + inputNewPassWord.addView(newPassWord); + inputNewPassWord.addView(viewNewPassword, viewParams); + final View viewConfirmPassWord = new View(G.fragmentActivity); + viewConfirmPassWord.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + newPassWord.setBackground(G.context.getResources().getDrawable(android.R.color.transparent)); + } + + TextInputLayout inputConfirmPassWord = new TextInputLayout(G.fragmentActivity); + final EditText confirmPassWord = new EditText(G.fragmentActivity); + confirmPassWord.setHint(G.fragmentActivity.getResources().getString(R.string.please_re_enter_your_password)); + confirmPassWord.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI); + confirmPassWord.setTypeface(G.typeface_IRANSansMobile); + confirmPassWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, G.context.getResources().getDimension(R.dimen.dp14)); + confirmPassWord.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); + confirmPassWord.setTransformationMethod(PasswordTransformationMethod.getInstance()); + confirmPassWord.setHintTextColor(G.context.getResources().getColor(R.color.hint_edit_text)); + confirmPassWord.setTextColor(G.context.getResources().getColor(R.color.text_edit_text)); + confirmPassWord.setPadding(0, 8, 0, 8); + confirmPassWord.setMaxLines(1); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + confirmPassWord.setBackground(G.context.getResources().getDrawable(android.R.color.transparent)); + } + inputConfirmPassWord.addView(confirmPassWord); + inputConfirmPassWord.addView(viewConfirmPassWord, viewParams); + + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + layoutParams.setMargins(0, 0, 0, 15); + LinearLayout.LayoutParams lastNameLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + lastNameLayoutParams.setMargins(0, 15, 0, 10); + + layoutNickname.addView(inputNewPassWord, layoutParams); + layoutNickname.addView(inputConfirmPassWord, lastNameLayoutParams); + + final MaterialDialog dialog = + new MaterialDialog.Builder(G.fragmentActivity) + .title(G.fragmentActivity.getResources().getString(R.string.please_set_password)) + .inputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD) + .positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)).customView(layoutNickname, true) + .widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + + final View positive = dialog.getActionButton(DialogAction.POSITIVE); + + newPassWord.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean b) { + if (b) { + viewNewPassword.setBackgroundColor(Color.parseColor(G.appBarColor)); + } else { + viewNewPassword.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); + } + } + }); + + confirmPassWord.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean b) { + if (b) { + viewConfirmPassWord.setBackgroundColor(Color.parseColor(G.appBarColor)); + } else { + viewConfirmPassWord.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); + } + } + }); + + positive.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + startSavePin(newPassWord.getText().toString(), confirmPassWord.getText().toString()); + dialog.dismiss(); + + } + }); + + dialog.show(); + } + + /** + * set new password for wallet + * + * @param newPassword + * @param confirmPassword + */ + + private void startSavePin(String newPassword, String confirmPassword) { + String[] data = new String[]{newPassword, + confirmPassword,}; + if ((RaadApp.paygearCard.isProtected && TextUtils.isEmpty(data[0])) || TextUtils.isEmpty(data[1])) { + HelperError.showSnackMessage(G.fragmentActivity.getResources().getString(R.string.please_enter_your_password), true); + return; + } + + if (!data[0].equals(data[1])) { + HelperError.showSnackMessage(G.fragmentActivity.getResources().getString(R.string.Password_dose_not_match), true); + return; + } + + Map map = new HashMap<>(); + if (RaadApp.paygearCard.isProtected) + map.put("old_password", data[0]); + map.put("new_password", data[1]); + + Web.getInstance().getWebService().setCreditCardPin(RaadApp.paygearCard.token, PostRequest.getRequestBody(map)).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Boolean success = Web.checkResponse(PaymentFragment.this, call, response); + if (success == null) + return; + + if (success) { + HelperError.showSnackMessage(G.fragmentActivity.getResources().getString(R.string.card_pin_saved), false); + RaadApp.paygearCard.isProtected = true; + fragmentActivity.onBackPressed(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + if (Web.checkFailureResponse(PaymentFragment.this, call, t)) { + } + } + }); + } + + + /** + * confirm password + */ + + public void setConfirmPassword(final PaymentAuth paymentAuth) { + final LinearLayout layoutNickname = new LinearLayout(G.fragmentActivity); + layoutNickname.setOrientation(LinearLayout.VERTICAL); + + final View viewFirstName = new View(G.fragmentActivity); + viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); + LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); + + TextInputLayout inputNewPassWord = new TextInputLayout(G.fragmentActivity); + final EditText newPassWord = new EditText(G.fragmentActivity); + newPassWord.setHint(G.fragmentActivity.getResources().getString(R.string.please_enter_your_password)); + newPassWord.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI); + newPassWord.setTypeface(G.typeface_IRANSansMobile); + newPassWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, G.context.getResources().getDimension(R.dimen.dp14)); + newPassWord.setTextColor(G.context.getResources().getColor(R.color.text_edit_text)); + newPassWord.setHintTextColor(G.context.getResources().getColor(R.color.hint_edit_text)); + newPassWord.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD); + newPassWord.setTransformationMethod(PasswordTransformationMethod.getInstance()); + newPassWord.setPadding(0, 8, 0, 8); + newPassWord.setMaxLines(1); + inputNewPassWord.addView(newPassWord); + inputNewPassWord.addView(viewFirstName, viewParams); + final View viewLastName = new View(G.fragmentActivity); + viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + newPassWord.setBackground(G.context.getResources().getDrawable(android.R.color.transparent)); + } + + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + layoutParams.setMargins(0, 0, 0, 15); + LinearLayout.LayoutParams lastNameLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + lastNameLayoutParams.setMargins(0, 15, 0, 10); + + layoutNickname.addView(inputNewPassWord, layoutParams); + + final MaterialDialog dialog = + new MaterialDialog.Builder(G.fragmentActivity) + .title(G.fragmentActivity.getResources().getString(R.string.your_password)) + .inputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD) + .positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)).customView(layoutNickname, true) + .widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + + final View positive = dialog.getActionButton(DialogAction.POSITIVE); + + newPassWord.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean b) { + if (b) { + viewFirstName.setBackgroundColor(Color.parseColor(G.appBarColor)); + } else { + viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); + } + } + }); + + + positive.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (!TextUtils.isEmpty(newPassWord.getText().toString().trim())) { + startPay(paymentAuth, newPassWord.getText().toString()); + dialog.dismiss(); + } else { + HelperError.showSnackMessage(G.fragmentActivity.getResources().getString(R.string.please_enter_your_password), true); + } + } + }); + + dialog.show(); + } + + private void showProgress() { + progressDialog = new MaterialDialog.Builder(fragmentActivity) + .content(R.string.please_wait) + .progress(true, 0) + .cancelable(false) + .canceledOnTouchOutside(false) + .autoDismiss(false) + .build(); + + progressDialog.show(); + } + + public void sendPost(String url, String token) { + Map finalInfoMap = new HashMap<>(); + finalInfoMap.put("token", token); + mAPIService = ApiUtils.getAPIService(); + mAPIService.sendToken(url, getRequestBody(finalInfoMap)).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + } + + @Override + public void onFailure(Call call, Throwable t) { + } + }); + + } + + public static RequestBody getRequestBody(Object object) { + Gson gson = new Gson(); + String json = gson.toJson(object); + return RequestBody.create(MediaType.parse("application/json"), json); + } + + @Override + public void onPause() { + super.onPause(); + + } +} + diff --git a/app/src/main/java/net/iGap/eventbus/socketMessages.java b/app/src/main/java/net/iGap/eventbus/socketMessages.java new file mode 100644 index 0000000..15b91fa --- /dev/null +++ b/app/src/main/java/net/iGap/eventbus/socketMessages.java @@ -0,0 +1,10 @@ +package net.iGap.eventbus; + +public class socketMessages { + + public static final int FAILED = 0; + public static final int SUCCESS = 1; + public static final int PaymentResultRecievedSuccess = 2; + public static final int PaymentResultRecievedFailed = 3; + public static final int PaymentResultNotRecieved = 4; +} diff --git a/app/src/main/java/net/iGap/fragments/FragmentBlockedUser.java b/app/src/main/java/net/iGap/fragments/FragmentBlockedUser.java index 42c6018..ea4a7c7 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentBlockedUser.java +++ b/app/src/main/java/net/iGap/fragments/FragmentBlockedUser.java @@ -304,10 +304,9 @@ public void onBindViewHolder(final BlockListAdapter.ViewHolder viewHolder, int i } viewHolder.title.setText(registeredInfo.getDisplayName()); - if (G.isDarkTheme) { - viewHolder.title.setTextColor(Color.parseColor(G.textTitleTheme)); - viewHolder.subtitle.setTextColor(Color.parseColor(G.textSubTheme)); - } + + viewHolder.title.setTextColor(Color.parseColor(G.textTitleTheme)); + viewHolder.subtitle.setTextColor(Color.parseColor(G.textSubTheme)); viewHolder.subtitle.setText(LastSeenTimeUtil.computeTime(registeredInfo.getId(), registeredInfo.getLastSeen(), false)); if (HelperCalander.isPersianUnicode) { viewHolder.subtitle.setText(viewHolder.subtitle.getText().toString()); diff --git a/app/src/main/java/net/iGap/fragments/FragmentChannelProfile.java b/app/src/main/java/net/iGap/fragments/FragmentChannelProfile.java index 180e6e0..49bda3b 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentChannelProfile.java +++ b/app/src/main/java/net/iGap/fragments/FragmentChannelProfile.java @@ -3,7 +3,9 @@ import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.ColorStateList; import android.databinding.DataBindingUtil; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; @@ -46,6 +48,7 @@ import net.iGap.module.CircleImageView; import net.iGap.module.FileUploadStructure; import net.iGap.module.SUID; +import net.iGap.module.structs.StructBottomSheet; import net.iGap.proto.ProtoGlobal; import net.iGap.request.RequestChannelAvatarAdd; import net.iGap.request.RequestChannelKickAdmin; @@ -55,6 +58,7 @@ import java.io.File; import java.io.IOException; +import java.util.HashMap; public class FragmentChannelProfile extends BaseFragment implements OnChannelAvatarAdd, OnChannelAvatarDelete { @@ -101,6 +105,10 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { FloatingActionButton fab = fragmentProfileChannelBinding.pchFabAddToChannel; + + fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom))); + fab.setColorFilter(Color.WHITE); + prgWait = fragmentProfileChannelBinding.agpPrgWaiting; AppUtils.setProgresColler(prgWait); @@ -186,7 +194,7 @@ public void run() { FragmentEditImage.completeEditImage = new FragmentEditImage.CompleteEditImage() { @Override - public void result(String path, String message) { + public void result(String path, String message, HashMap textImageList) { pathSaveImage = null; pathSaveImage = path; long avatarId = SUID.id().get(); @@ -444,23 +452,32 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { String filePath = null; long avatarId = SUID.id().get(); + + if (FragmentEditImage.textImageList != null) FragmentEditImage.textImageList.clear(); + if (FragmentEditImage.itemGalleryList != null) + FragmentEditImage.itemGalleryList.clear(); + switch (requestCode) { case AttachFile.request_code_TAKE_PICTURE: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ImageHelper.correctRotateImage(AttachFile.mCurrentPhotoPath, true); //rotate image - new HelperFragment(FragmentEditImage.newInstance(AttachFile.mCurrentPhotoPath, false, false)).setReplace(false).load(); + + FragmentEditImage.insertItemList(AttachFile.mCurrentPhotoPath, false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); } else { ImageHelper.correctRotateImage(AttachFile.imagePath, true); //rotate image - new HelperFragment(FragmentEditImage.newInstance(AttachFile.imagePath, false, false)).setReplace(false).load(); + + FragmentEditImage.insertItemList(AttachFile.imagePath, false); + new HelperFragment(FragmentEditImage.newInstance(AttachFile.imagePath, false, false, 0)).setReplace(false).load(); } break; case AttachFile.request_code_image_from_gallery_single_select: if (data.getData() == null) { return; } -// - new HelperFragment(FragmentEditImage.newInstance(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false, false)).setReplace(false).load(); + FragmentEditImage.insertItemList(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); break; } } diff --git a/app/src/main/java/net/iGap/fragments/FragmentChat.java b/app/src/main/java/net/iGap/fragments/FragmentChat.java index c4494a3..bb22100 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentChat.java +++ b/app/src/main/java/net/iGap/fragments/FragmentChat.java @@ -87,6 +87,7 @@ import net.iGap.Config; import net.iGap.G; import net.iGap.R; +import net.iGap.Theme; import net.iGap.activities.ActivityCall; import net.iGap.activities.ActivityMain; import net.iGap.activities.ActivityTrimVideo; @@ -103,6 +104,7 @@ import net.iGap.adapter.items.chat.ImageWithTextItem; import net.iGap.adapter.items.chat.LocationItem; import net.iGap.adapter.items.chat.LogItem; +import net.iGap.adapter.items.chat.LogWallet; import net.iGap.adapter.items.chat.ProgressWaiting; import net.iGap.adapter.items.chat.TextItem; import net.iGap.adapter.items.chat.TimeItem; @@ -111,6 +113,8 @@ import net.iGap.adapter.items.chat.VideoWithTextItem; import net.iGap.adapter.items.chat.ViewMaker; import net.iGap.adapter.items.chat.VoiceItem; +import net.iGap.databinding.PaymentDialogBinding; +import net.iGap.eventbus.PaymentFragment; import net.iGap.helper.HelperAvatar; import net.iGap.helper.HelperCalander; import net.iGap.helper.HelperDownloadFile; @@ -274,8 +278,10 @@ import java.util.Calendar; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; import io.fabric.sdk.android.services.concurrency.AsyncTask; @@ -371,10 +377,11 @@ public class FragmentChat extends BaseFragment private MaterialDesignTextView imvSendButton; private MaterialDesignTextView imvAttachFileButton; private MaterialDesignTextView imvMicButton; + private MaterialDesignTextView sendMoney; // private MaterialDesignTextView btnReplaySelected; private RippleView rippleDeleteSelected; private RippleView rippleReplaySelected; - private ArrayList listPathString; + public static ArrayList listPathString; private MaterialDesignTextView btnCancelSendingFile; private ViewGroup viewGroupLastSeen; private CircleImageView imvUserPicture; @@ -396,6 +403,7 @@ public class FragmentChat extends BaseFragment private GroupChatRole groupRole; private ChannelChatRole channelRole; private PopupWindow popupWindow; + private MaterialDialog dialogWait; private Uri latestUri; private Calendar lastDateCalendar = Calendar.getInstance(); private MaterialDesignTextView iconMute; @@ -424,7 +432,6 @@ public class FragmentChat extends BaseFragment private View viewBottomSheet; private View viewBottomSheetForward; private Fotoapparat fotoapparatSwitcher; - private ArrayList itemGalleryList = new ArrayList(); private RealmRoomMessage firstUnreadMessage; private RealmRoomMessage firstUnreadMessageInChat; // when user is in this room received new message private RealmRoomMessage voiceLastMessage = null; @@ -463,7 +470,6 @@ public class FragmentChat extends BaseFragment private String userStatus; private Boolean isGoingFromUserLink = false; private Boolean isNotJoin = false; // this value will be trued when come to this chat with username - private boolean isCheckBottomSheet = false; private boolean firsInitScrollPosition = false; private boolean initHash = false; private boolean initAttach = false; @@ -478,6 +484,7 @@ public class FragmentChat extends BaseFragment private boolean isCloudRoom; private boolean isEditMessage = false; private long biggestMessageId = 0; + private long lastMessageId = 0; private long replyToMessageId = 0; private long userId; private long lastSeen; @@ -506,6 +513,8 @@ public class FragmentChat extends BaseFragment private ArrayList mListForwardNotExict = new ArrayList<>(); private String messageEdit = ""; private boolean isNewBottomSheet = true; + PaymentDialogBinding paymentDialogBinding; + PaymentFragment paymentDialog; public static Realm getRealmChat() { if (realmChat == null || realmChat.isClosed()) { @@ -537,13 +546,7 @@ public static void removeResendList(long messageId) { * get images for show in bottom sheet */ public static ArrayList getAllShownImagesPath(Activity activity) { - ArrayList listOfAllImages = new ArrayList<>(); - - if (!HelperPermission.grantedUseStorage()) { - return listOfAllImages; - } - Uri uri; Cursor cursor; int column_index_data = 0, column_index_folder_name; @@ -565,13 +568,13 @@ public static ArrayList getAllShownImagesPath(Activity activi absolutePathOfImage = cursor.getString(column_index_data); StructBottomSheet item = new StructBottomSheet(); + item.setId(listOfAllImages.size()); item.setPath(absolutePathOfImage); item.isSelected = true; listOfAllImages.add(0, item); } cursor.close(); } - return listOfAllImages; } @@ -749,7 +752,7 @@ public void run() { public void onSuccess() { /** * hint: should use from this method here because we need checkAction - * state after set members count for avoid from hide action if exist + * changeState after set members count for avoid from hide action if exist */ checkAction(); @@ -1104,10 +1107,11 @@ public void onActivityResult(final int requestCode, int resultCode, Intent data) setDraftMessage(requestCode); } else { compressedPath.put(listPathString.get(0), true); + showDraftLayout(); + setDraftMessage(requestCode); } } - showDraftLayout(); - setDraftMessage(requestCode); + } else { /** * set compressed true for use this path @@ -1152,10 +1156,19 @@ public void run() { if (requestCode == AttachFile.requestOpenGalleryForImageMultipleSelect) { if (!listPathString.get(0).toLowerCase().endsWith(".gif")) { + if (FragmentEditImage.itemGalleryList == null) { + FragmentEditImage.itemGalleryList = new ArrayList<>(); + } + + FragmentEditImage.itemGalleryList.clear(); + FragmentEditImage.textImageList.clear(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - listPathString.set(0, attachFile.saveGalleryPicToLocal(listPathString.get(0))); +// listPathString.set(0, attachFile.saveGalleryPicToLocal(listPathString.get(0))); Uri uri = Uri.parse(listPathString.get(0)); - new HelperFragment(FragmentEditImage.newInstance(AttachFile.getFilePathFromUriAndCheckForAndroid7(uri, HelperGetDataFromOtherApp.FileType.image), true, false)).setReplace(false).load(); + + FragmentEditImage.insertItemList(AttachFile.getFilePathFromUriAndCheckForAndroid7(uri, HelperGetDataFromOtherApp.FileType.image), true); + new HelperFragment(FragmentEditImage.newInstance(null, true, false, 0)).setReplace(false).load(); G.handler.post(new Runnable() { @Override @@ -1166,9 +1179,11 @@ public void run() { } }); } else { - listPathString.set(0, attachFile.saveGalleryPicToLocal(listPathString.get(0))); +// listPathString.set(0, attachFile.saveGalleryPicToLocal(listPathString.get(0))); Uri uri = Uri.parse(listPathString.get(0)); - new HelperFragment(FragmentEditImage.newInstance(uri.toString(), true, false)).setReplace(false).load(); + FragmentEditImage.insertItemList(uri.toString(), true); + + new HelperFragment(FragmentEditImage.newInstance(null, true, false, 0)).setReplace(false).load(); G.handler.post(new Runnable() { @Override @@ -1191,10 +1206,21 @@ public void run() { } } else if (requestCode == AttachFile.request_code_TAKE_PICTURE) { + if (FragmentEditImage.itemGalleryList == null) { + FragmentEditImage.itemGalleryList = new ArrayList<>(); + } + + FragmentEditImage.itemGalleryList.clear(); + FragmentEditImage.textImageList.clear(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + ImageHelper.correctRotateImage(listPathString.get(0), true); - new HelperFragment(FragmentEditImage.newInstance(listPathString.get(0), true, false)).setReplace(false).load(); + + FragmentEditImage.insertItemList(listPathString.get(0), true); + + new HelperFragment(FragmentEditImage.newInstance(null, true, false, 0)).setReplace(false).load(); G.handler.post(new Runnable() { @Override public void run() { @@ -1205,7 +1231,9 @@ public void run() { }); } else { ImageHelper.correctRotateImage(listPathString.get(0), true); - new HelperFragment(FragmentEditImage.newInstance(listPathString.get(0), true, false)).setReplace(false).load(); + + FragmentEditImage.insertItemList(listPathString.get(0), true); + new HelperFragment(FragmentEditImage.newInstance(null, true, false, 0)).setReplace(false).load(); G.handler.post(new Runnable() { @Override public void run() { @@ -1215,6 +1243,9 @@ public void run() { } }); } + } else { + showDraftLayout(); + setDraftMessage(requestCode); } } else { @@ -1224,6 +1255,8 @@ public void run() { @Override public void run() { ImageHelper.correctRotateImage(listPathString.get(0), true); + showDraftLayout(); + setDraftMessage(requestCode); } }); thread.start(); @@ -1232,9 +1265,15 @@ public void run() { @Override public void run() { listPathString.set(0, attachFile.saveGalleryPicToLocal(listPathString.get(0))); + showDraftLayout(); + setDraftMessage(requestCode); } }); thread.start(); + } else { + showDraftLayout(); + setDraftMessage(requestCode); + } } } @@ -1507,6 +1546,7 @@ public void onError(int majorCode, int minorCode) { } }); } + messageId = extras.getLong("MessageId"); /** @@ -1535,6 +1575,11 @@ public void onError(int majorCode, int minorCode) { firstUnreadMessage = realmRoom.getFirstUnreadMessage(); savedScrollMessageId = realmRoom.getLastScrollPositionMessageId(); firstVisiblePositionOffset = realmRoom.getLastScrollPositionOffset(); + + if (messageId != 0) { + savedScrollMessageId = messageId; + firstVisiblePositionOffset = 0; + } if (isChatReadOnly) { viewAttachFile.setVisibility(View.GONE); (rootView.findViewById(R.id.chl_recycler_view_chat)).setPadding(0, 0, 0, 0); @@ -1583,6 +1628,34 @@ public void onError(int majorCode, int minorCode) { getDraft(); getUserInfo(); insertShearedData(HelperGetDataFromOtherApp.messageFileAddress); + + + FragmentShearedMedia.goToPositionFromShardMedia = new FragmentShearedMedia.GoToPositionFromShardMedia() { + @Override + public void goToPosition(Long messageId) { + + if (messageId != 0) { + savedScrollMessageId = messageId; + firstVisiblePositionOffset = 0; + + int position = mAdapter.findPositionByMessageId(savedScrollMessageId); + if (position > 0) { + LinearLayoutManager linearLayout = (LinearLayoutManager) recyclerView.getLayoutManager(); + linearLayout.scrollToPositionWithOffset(position, firstVisiblePositionOffset); + savedScrollMessageId = 0; + } else { + RealmRoomMessage rm = getRealmChat().where(RealmRoomMessage.class).equalTo(RealmRoomMessageFields.MESSAGE_ID, messageId).findFirst(); + rm = RealmRoomMessage.getFinalMessage(rm); + if (rm != null) { + resetMessagingValue(); + savedScrollMessageId = messageId; + firstVisiblePositionOffset = 0; + getMessages(); + } + } + } + } + }; } private void initPinedMessage() { @@ -1641,7 +1714,7 @@ public void run() { resetMessagingValue(); savedScrollMessageId = pinMessageId; firstVisiblePositionOffset = 0; - getMessages(); + setGapAndGetMessage(pinMessageId); } }); @@ -1756,7 +1829,7 @@ public boolean onBackPressed() { } /** - * get settings state and change view + * get settings changeState and change view */ private void pageSettings() { /** @@ -2081,6 +2154,7 @@ public void onClick(View rippleView) { ViewGroup root5 = (ViewGroup) v.findViewById(R.id.dialog_root_item5_notification); ViewGroup root6 = (ViewGroup) v.findViewById(R.id.dialog_root_item6_notification); ViewGroup root7 = (ViewGroup) v.findViewById(R.id.dialog_root_item7_notification); + ViewGroup root8 = (ViewGroup) v.findViewById(R.id.dialog_root_item10_sendMoney); TextView txtSearch = (TextView) v.findViewById(R.id.dialog_text_item1_notification); TextView txtClearHistory = (TextView) v.findViewById(R.id.dialog_text_item2_notification); @@ -2089,6 +2163,7 @@ public void onClick(View rippleView) { TextView txtChatToGroup = (TextView) v.findViewById(R.id.dialog_text_item5_notification); TextView txtCleanUp = (TextView) v.findViewById(R.id.dialog_text_item6_notification); TextView txtReport = (TextView) v.findViewById(R.id.dialog_text_item7_notification); + TextView txtSendMoney = (TextView) v.findViewById(R.id.dialog_text_item10_sendMoney); TextView iconSearch = (TextView) v.findViewById(R.id.dialog_icon_item1_notification); iconSearch.setText(G.fragmentActivity.getResources().getString(R.string.md_searching_magnifying_glass)); @@ -2110,12 +2185,17 @@ public void onClick(View rippleView) { TextView iconReport = (TextView) v.findViewById(R.id.dialog_icon_item7_notification); iconReport.setText(G.fragmentActivity.getResources().getString(R.string.md_igap_alert_box)); + + TextView iconSendMoney = (TextView) v.findViewById(R.id.dialog_icon_item10_sendMoney); + iconSendMoney.setText(G.fragmentActivity.getResources().getString(R.string.md_payment)); + root1.setVisibility(View.VISIBLE); root2.setVisibility(View.VISIBLE); root3.setVisibility(View.VISIBLE); root4.setVisibility(View.VISIBLE); root5.setVisibility(View.VISIBLE); root6.setVisibility(View.VISIBLE); + root8.setVisibility(View.GONE); txtSearch.setText(G.fragmentActivity.getResources().getString(R.string.Search)); txtClearHistory.setText(G.fragmentActivity.getResources().getString(R.string.clear_history)); @@ -2124,6 +2204,7 @@ public void onClick(View rippleView) { txtChatToGroup.setText(G.fragmentActivity.getResources().getString(R.string.chat_to_group)); txtCleanUp.setText(G.fragmentActivity.getResources().getString(R.string.clean_up)); txtReport.setText(G.fragmentActivity.getResources().getString(R.string.report)); + txtSendMoney.setText(G.fragmentActivity.getResources().getString(R.string.SendMoney)); if (chatType == CHAT) { root3.setVisibility(View.VISIBLE); @@ -2179,6 +2260,13 @@ public void onClick(View rippleView) { root7.setVisibility(View.GONE); } + + if (G.isWalletActive && G.isWalletRegister && (chatType == CHAT) && !isCloudRoom) { + root8.setVisibility(View.VISIBLE); + } else { + root8.setVisibility(View.GONE); + } + //realm.close(); root1.setOnClickListener(new View.OnClickListener() { @@ -2282,6 +2370,19 @@ public void onClick(View v) { dialogReport(false, 0); } }); + + + /** + * send Money + */ + root8.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + showPaymentDialog(); + + } + }); } }); @@ -2313,6 +2414,13 @@ public void onClick(View v) { imvMicButton = (MaterialDesignTextView) rootView.findViewById(R.id.chl_imv_mic_button); + sendMoney = (MaterialDesignTextView) rootView.findViewById(R.id.chl_imv_sendMoney_button); + if (G.isWalletActive && G.isWalletRegister && (chatType == CHAT) && !isCloudRoom) { + sendMoney.setVisibility(View.VISIBLE); + } else { + sendMoney.setVisibility(View.GONE); + } + mAdapter = new MessagesAdapter<>(this, this, this); mAdapter.getItemFilter().withFilterPredicate(new IItemAdapter.Predicate() { @@ -2648,6 +2756,7 @@ public void run() { final RealmRoomMessage roomMessage = RealmRoomMessage.makeTextMessage(mRoomId, message, replyMessageId()); if (roomMessage != null) { edtChat.setText(""); + lastMessageId = roomMessage.getMessageId(); mAdapter.add(new TextItem(getRealmChat(), chatType, FragmentChat.this).setMessage(StructMessageInfo.convert(getRealmChat(), roomMessage)).withIdentifier(SUID.id().get())); clearReplyView(); scrollToEnd(); @@ -2683,7 +2792,9 @@ public void run() { public void openBottomSheet(boolean isNew) { isNewBottomSheet = isNew; imvAttachFileButton.performClick(); + fastItemAdapter.notifyAdapterDataSetChanged(); } + }; imvAttachFileButton.setOnClickListener(new View.OnClickListener() { @@ -2696,11 +2807,21 @@ public void onClick(View view) { } InputMethodManager imm = (InputMethodManager) G.fragmentActivity.getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + if (imm != null) { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } itemAdapterBottomSheet(); } }); + sendMoney.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showPaymentDialog(); + } + }); + + imvMicButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { @@ -3486,7 +3607,7 @@ public void onOpenClick(View view, StructMessageInfo message, int pos) { if (messageType == ProtoGlobal.RoomMessageType.IMAGE || messageType == IMAGE_TEXT) { showImage(message, view); } else if (messageType == VIDEO || messageType == VIDEO_TEXT) { - if (sharedPreferences.getInt(SHP_SETTING.KEY_DEFAULT_PLAYER, 0) == 1) { + if (sharedPreferences.getInt(SHP_SETTING.KEY_DEFAULT_PLAYER, 1) == 0) { openMessage(message); } else { showImage(message, view); @@ -4014,7 +4135,7 @@ public void onClick(View v) { final String _path = AndroidUtils.getFilePathWithCashId(cacheId, name, _messageType); if (fileToken != null && fileToken.length() > 0 && size > 0) { - HelperDownloadFile.startDownload(message.messageID, fileToken, fileUrl, cacheId, name, size, selector, _path, 0, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(message.messageID, fileToken, fileUrl, cacheId, name, size, selector, _path, 0, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(String path, int progress) { @@ -4516,10 +4637,10 @@ private ArrayList getMessageStructFromSelectedItems() { } /** - * show current state for user if this room is chat + * show current changeState for user if this room is chat * - * @param status current state - * @param time if state is not online set latest online time + * @param status current changeState + * @param time if changeState is not online set latest online time */ private void setUserStatus(final String status, final long time) { if (G.connectionState == ConnectionState.CONNECTING || G.connectionState == ConnectionState.WAITING_FOR_NETWORK) { @@ -4539,7 +4660,7 @@ public void run() { //} ViewMaker.setLayoutDirection(viewGroupLastSeen, View.LAYOUT_DIRECTION_LTR); } else { - if (status != null) { + if (status != null && txtLastSeen != null) { if (status.equals(ProtoGlobal.RegisteredUser.Status.EXACTLY.toString())) { txtLastSeen.setText(LastSeenTimeUtil.computeTime(chatPeerId, time, true, false)); } else { @@ -4656,8 +4777,12 @@ public void execute(Realm realm) { private void showErrorDialog(final int time) { + if (dialogWait != null && dialogWait.isShowing()) { + return; + } + boolean wrapInScrollView = true; - final MaterialDialog dialogWait = new MaterialDialog.Builder(G.currentActivity).title(G.fragmentActivity.getResources().getString(R.string.title_limit_chat_to_unknown_contact)).customView(R.layout.dialog_remind_time, wrapInScrollView).positiveText(R.string.B_ok).autoDismiss(false).canceledOnTouchOutside(true).onPositive(new MaterialDialog.SingleButtonCallback() { + dialogWait = new MaterialDialog.Builder(G.currentActivity).title(G.fragmentActivity.getResources().getString(R.string.title_limit_chat_to_unknown_contact)).customView(R.layout.dialog_remind_time, wrapInScrollView).positiveText(R.string.B_ok).autoDismiss(false).canceledOnTouchOutside(true).onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { dialog.dismiss(); @@ -4817,7 +4942,9 @@ private void deleteItem(final long messageId, int position) { } } - mAdapter.removeMessage(position); + if (position >= 0) { + mAdapter.removeMessage(position); + } RealmRoomMessage.deleteMessage(messageId); } @@ -5024,35 +5151,61 @@ private void saveMessageIdPositionState(final long messageId) { * emoji initialization */ private void setUpEmojiPopup() { - emojiPopup = EmojiPopup.Builder.fromRootView(rootView.findViewById(ac_ll_parent)).setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() { + switch (G.themeColor) { + case Theme.BLUE_GREY_COMPLETE: + case Theme.INDIGO_COMPLETE: + case Theme.BROWN_COMPLETE: + case Theme.GREY_COMPLETE: + case Theme.TEAL_COMPLETE: + case Theme.DARK: + + setEmojiColor(G.backgroundTheme_2, G.textTitleTheme, G.textTitleTheme); + break; + default: + setEmojiColor("#eceff1", "#61000000", "#61000000"); - @Override - public void onEmojiBackspaceClick(View v) { - } - }).setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() { - @Override - public void onEmojiPopupShown() { - changeEmojiButtonImageResource(R.string.md_black_keyboard_with_white_keys); - isEmojiSHow = true; - } - }).setOnSoftKeyboardOpenListener(new OnSoftKeyboardOpenListener() { - @Override - public void onKeyboardOpen(final int keyBoardHeight) { + } + + } + + private void setEmojiColor(String BackgroundColor, String iconColor, String dividerColor) { + + emojiPopup = EmojiPopup.Builder.fromRootView(rootView.findViewById(R.id.ac_ll_parent)) + .setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() { + + @Override + public void onEmojiBackspaceClick(View v) { + + } + }).setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() { + @Override + public void onEmojiPopupShown() { + changeEmojiButtonImageResource(R.string.md_black_keyboard_with_white_keys); + isEmojiSHow = true; + } + }).setOnSoftKeyboardOpenListener(new OnSoftKeyboardOpenListener() { + @Override + public void onKeyboardOpen(final int keyBoardHeight) { + + } + }).setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() { + @Override + public void onEmojiPopupDismiss() { + changeEmojiButtonImageResource(R.string.md_emoticon_with_happy_face); + isEmojiSHow = false; + } + }).setOnSoftKeyboardCloseListener(new OnSoftKeyboardCloseListener() { + @Override + public void onKeyboardClose() { + emojiPopup.dismiss(); + } + }) + .setBackgroundColor(Color.parseColor(BackgroundColor)) + .setIconColor(Color.parseColor(iconColor)) + .setDividerColor(Color.parseColor(dividerColor)) + .build(edtChat); - } - }).setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() { - @Override - public void onEmojiPopupDismiss() { - changeEmojiButtonImageResource(R.string.md_emoticon_with_happy_face); - isEmojiSHow = false; - } - }).setOnSoftKeyboardCloseListener(new OnSoftKeyboardCloseListener() { - @Override - public void onKeyboardClose() { - emojiPopup.dismiss(); - } - }).build(edtChat); } private void changeEmojiButtonImageResource(@StringRes int drawableResourceId) { @@ -5261,7 +5414,7 @@ private void clearDraftRequest() { private void insertShearedData(final ArrayList pathList) { /** * run this method with delay , because client get local message with delay - * for show messages with async state and before run getLocalMessage this shared + * for show messages with async changeState and before run getLocalMessage this shared * item added to realm and view, and after that getLocalMessage called and new item * got from realm and add to view again but in this time from getLocalMessage method */ @@ -5376,7 +5529,9 @@ private void shearedDataToOtherProgram(StructMessageInfo messageInfo) { intent.putExtra(Intent.EXTRA_TEXT, messageContact); break; case "LOCATION": - String imagePathPosition = messageInfo.forwardedFrom != null ? messageInfo.forwardedFrom.getLocation().getImagePath() : messageInfo.location.getImagePath(); + String imagePathPosition = messageInfo.forwardedFrom != null ? + AppUtils.getLocationPath(messageInfo.forwardedFrom.getLocation().getLocationLat(), messageInfo.forwardedFrom.getLocation().getLocationLong()) : + AppUtils.getLocationPath(messageInfo.location.getLocationLat(), messageInfo.location.getLocationLong()); intent.setType("image/*"); if (imagePathPosition != null) { intent.putExtra(Intent.EXTRA_STREAM, AppUtils.createtUri(new File(imagePathPosition))); @@ -5397,7 +5552,7 @@ private void shearedDataToOtherProgram(StructMessageInfo messageInfo) { break; case "VIDEO": case "VIDEO_TEXT": - intent.setType("image/*"); + intent.setType("video/*"); AppUtils.shareItem(intent, messageInfo); chooserDialogText = G.fragmentActivity.getResources().getString(R.string.share_video_file); break; @@ -5414,7 +5569,7 @@ private void shearedDataToOtherProgram(StructMessageInfo messageInfo) { if (mimeType == null || mimeType.length() < 1) { mimeType = "*/*"; } else { - mimeType = "application/" + mimeType; + mimeType = "application/*" + mimeType; } intent.setType(mimeType); intent.putExtra(Intent.EXTRA_STREAM, uri); @@ -5438,7 +5593,7 @@ public void run() { } /** - * init layout for hashtak up and down + * init layout for hashtag up and down */ private void initLayoutHashNavigationCallback() { @@ -5783,37 +5938,83 @@ private void initAttach() { ViewGroup video = (ViewGroup) viewBottomSheet.findViewById(R.id.video); ViewGroup music = (ViewGroup) viewBottomSheet.findViewById(R.id.music); ViewGroup document = (ViewGroup) viewBottomSheet.findViewById(R.id.document); - ViewGroup close = (ViewGroup) viewBottomSheet.findViewById(R.id.close); + final ViewGroup close = (ViewGroup) viewBottomSheet.findViewById(R.id.close); ViewGroup file = (ViewGroup) viewBottomSheet.findViewById(R.id.file); ViewGroup paint = (ViewGroup) viewBottomSheet.findViewById(R.id.paint); ViewGroup location = (ViewGroup) viewBottomSheet.findViewById(R.id.location); ViewGroup contact = (ViewGroup) viewBottomSheet.findViewById(R.id.contact); + + TextView txtCamera = (TextView) viewBottomSheet.findViewById(R.id.txtCamera); + TextView textPicture = (TextView) viewBottomSheet.findViewById(R.id.textPicture); + TextView txtVideo = (TextView) viewBottomSheet.findViewById(R.id.txtVideo); + TextView txtMusic = (TextView) viewBottomSheet.findViewById(R.id.txtMusic); + TextView txtDocument = (TextView) viewBottomSheet.findViewById(R.id.txtDocument); + TextView txtFile = (TextView) viewBottomSheet.findViewById(R.id.txtFile); + TextView txtPaint = (TextView) viewBottomSheet.findViewById(R.id.txtPaint); + TextView txtLocation = (TextView) viewBottomSheet.findViewById(R.id.txtLocation); + TextView txtContact = (TextView) viewBottomSheet.findViewById(R.id.txtContact); + TextView txtCamera2 = (TextView) viewBottomSheet.findViewById(R.id.txtCamera2); + TextView textPicture2 = (TextView) viewBottomSheet.findViewById(R.id.textPicture2); + TextView txtVideo2 = (TextView) viewBottomSheet.findViewById(R.id.txtVideo2); + TextView txtMusic2 = (TextView) viewBottomSheet.findViewById(R.id.txtMusic2); + TextView txtDocument2 = (TextView) viewBottomSheet.findViewById(R.id.txtDocument2); + TextView txtFile2 = (TextView) viewBottomSheet.findViewById(R.id.txtFile2); + TextView txtPaint2 = (TextView) viewBottomSheet.findViewById(R.id.txtPaint2); + TextView txtLocation2 = (TextView) viewBottomSheet.findViewById(R.id.txtLocation2); + TextView txtContact2 = (TextView) viewBottomSheet.findViewById(R.id.txtContact2); + send = (TextView) viewBottomSheet.findViewById(R.id.txtSend); + + txtCamera.setTextColor(Color.parseColor(G.attachmentColor)); + textPicture.setTextColor(Color.parseColor(G.attachmentColor)); + txtVideo.setTextColor(Color.parseColor(G.attachmentColor)); + txtMusic.setTextColor(Color.parseColor(G.attachmentColor)); + txtDocument.setTextColor(Color.parseColor(G.attachmentColor)); + txtFile.setTextColor(Color.parseColor(G.attachmentColor)); + txtPaint.setTextColor(Color.parseColor(G.attachmentColor)); + txtLocation.setTextColor(Color.parseColor(G.attachmentColor)); + txtContact.setTextColor(Color.parseColor(G.attachmentColor)); + send.setTextColor(Color.parseColor(G.attachmentColor)); + txtCountItem.setTextColor(Color.parseColor(G.attachmentColor)); + + txtCamera2.setTextColor(Color.parseColor(G.attachmentColor)); + textPicture2.setTextColor(Color.parseColor(G.attachmentColor)); + txtVideo2.setTextColor(Color.parseColor(G.attachmentColor)); + txtMusic2.setTextColor(Color.parseColor(G.attachmentColor)); + txtDocument2.setTextColor(Color.parseColor(G.attachmentColor)); + txtFile2.setTextColor(Color.parseColor(G.attachmentColor)); + txtPaint2.setTextColor(Color.parseColor(G.attachmentColor)); + txtLocation2.setTextColor(Color.parseColor(G.attachmentColor)); + txtContact2.setTextColor(Color.parseColor(G.attachmentColor)); + + onPathAdapterBottomSheet = new OnPathAdapterBottomSheet() { @Override - public void path(String path, boolean isCheck, boolean isEdit) { - - if (isCheck) { - listPathString.add(path); - } else { - listPathString.remove(path); - } + public void path(String path, boolean isCheck, boolean isEdit, StructBottomSheet mList, int id) { if (isEdit) { bottomSheetDialog.dismiss(); - new HelperFragment(FragmentEditImage.newInstance(path, true, false)).setReplace(false).load(); +// FragmentEditImage.itemGalleryList.set(id, mList); +// fastItemAdapter.notifyAdapterDataSetChanged(); + new HelperFragment(FragmentEditImage.newInstance(null, true, false, id)).setReplace(false).load(); // new HelperFragment(FragmentFilterImage.newInstance(path)).setReplace(false).load(); } else { - listPathString.size(); - if (listPathString.size() > 0) { - //send.setText(R.mipmap.send2); + if (isCheck) { +// listPathString.add(path); + StructBottomSheet item = new StructBottomSheet(); + item.setPath(path); + item.setText(""); + item.setId(id); + FragmentEditImage.textImageList.put(path, item); + } else { +// listPathString.remove(path); + FragmentEditImage.textImageList.remove(path); + } + if (FragmentEditImage.textImageList.size() > 0) { send.setText(G.fragmentActivity.getResources().getString(R.string.md_send_button)); - isCheckBottomSheet = true; - txtCountItem.setText("" + listPathString.size() + " " + G.fragmentActivity.getResources().getString(item)); + txtCountItem.setText("" + FragmentEditImage.textImageList.size() + " " + G.fragmentActivity.getResources().getString(item)); } else { - //send.setImageResource(R.mipmap.ic_close); send.setText(G.fragmentActivity.getResources().getString(R.string.igap_chevron_double_down)); - isCheckBottomSheet = false; txtCountItem.setText(G.fragmentActivity.getResources().getString(R.string.navigation_drawer_close)); } } @@ -5823,17 +6024,43 @@ public void path(String path, boolean isCheck, boolean isEdit) { FragmentEditImage.completeEditImage = new FragmentEditImage.CompleteEditImage() { @Override - public void result(String path, String message) { + public void result(String path, String message, HashMap textImageList) { listPathString = null; listPathString = new ArrayList<>(); - listPathString.add(path); - edtChat.setText(message); - latestRequestCode = AttachFile.requestOpenGalleryForImageMultipleSelect; - ll_attach_text.setVisibility(View.VISIBLE); - imvSendButton.performClick(); + + if (textImageList.size() == 0) { + return; + } + + /** + * sort list + */ + ArrayList itemList = new ArrayList(); + for (Map.Entry items : textImageList.entrySet()) { + itemList.add(items.getValue()); + } + + Collections.sort(itemList); + + for (StructBottomSheet item : itemList) { + edtChat.setText(item.getText()); + listPathString.add(item.getPath()); + latestRequestCode = AttachFile.requestOpenGalleryForImageMultipleSelect; + ll_attach_text.setVisibility(View.VISIBLE); + imvSendButton.performClick(); + } +// for (Map.Entry items : textImageList.entrySet()) { +// +// edtChat.setText(items.getValue().getText()); +// listPathString.add(items.getValue().getPath()); +// latestRequestCode = AttachFile.requestOpenGalleryForImageMultipleSelect; +// ll_attach_text.setVisibility(View.VISIBLE); +// imvSendButton.performClick(); +// } + +// close.performClick(); } }; - rcvBottomSheet = (RecyclerView) viewBottomSheet.findViewById(R.id.rcvContent); rcvBottomSheet.setLayoutManager(new GridLayoutManager(G.fragmentActivity, 1, GridLayoutManager.HORIZONTAL, false)); rcvBottomSheet.setItemViewCacheSize(100); @@ -6088,14 +6315,22 @@ public void onPick(ArrayList selectedPathList) { @Override public void onClick(View v) { - if (isCheckBottomSheet) { + if (FragmentEditImage.textImageList.size() > 0) { bottomSheetDialog.dismiss(); - fastItemAdapter.clear(); //send.setImageResource(R.mipmap.ic_close); send.setText(G.fragmentActivity.getResources().getString(R.string.igap_chevron_double_down)); txtCountItem.setText(G.fragmentActivity.getResources().getString(R.string.navigation_drawer_close)); + /** + * sort list + */ + final ArrayList itemList = new ArrayList(); + for (Map.Entry items : FragmentEditImage.textImageList.entrySet()) { + itemList.add(items.getValue()); + } + Collections.sort(itemList); + new Thread(new Runnable() { @Override public void run() { @@ -6103,19 +6338,23 @@ public void run() { @Override public void run() { - if (listPathString.size() == 1) { + if (itemList.size() == 1) { showDraftLayout(); - listPathString.set(0, attachFile.saveGalleryPicToLocal(listPathString.get(0))); + listPathString.add(itemList.get(0).getPath()); + listPathString.set(0, attachFile.saveGalleryPicToLocal(itemList.get(0).getPath())); setDraftMessage(AttachFile.requestOpenGalleryForImageMultipleSelect); latestRequestCode = AttachFile.requestOpenGalleryForImageMultipleSelect; //sendMessage(AttachFile.requestOpenGalleryForImageMultipleSelect, pathStrings.get(0)); } else { - for (String path : listPathString) { + for (StructBottomSheet items : itemList) { + //if (!path.toLowerCase().endsWith(".gif")) { - String localPathNew = attachFile.saveGalleryPicToLocal(path); + String localPathNew = attachFile.saveGalleryPicToLocal(items.path); + edtChat.setText(items.getText()); sendMessage(AttachFile.requestOpenGalleryForImageMultipleSelect, localPathNew); //} } + } } @@ -6616,35 +6855,72 @@ public void run() { } public void itemAdapterBottomSheet() { - listPathString.clear(); - if (isNewBottomSheet) { - fastItemAdapter.clear(); - itemGalleryList.clear(); - itemGalleryList = getAllShownImagesPath(G.fragmentActivity); + + if (fastItemAdapter != null) fastItemAdapter.clear(); + + if (isNewBottomSheet || FragmentEditImage.itemGalleryList.size() <= 1) { + + if (listPathString != null) { + listPathString.clear(); + } else { + listPathString = new ArrayList<>(); + } + + FragmentEditImage.itemGalleryList.clear(); + if (isNewBottomSheet) { + FragmentEditImage.textImageList.clear(); + } + + try { + HelperPermission.getStoragePermision(G.fragmentActivity, new OnGetPermission() { + @Override + public void Allow() throws IOException { + FragmentEditImage.itemGalleryList = getAllShownImagesPath(G.fragmentActivity); + if (rcvBottomSheet != null) rcvBottomSheet.setVisibility(View.VISIBLE); + checkCameraAndLoadImage(); + } + + @Override + public void deny() { + loadImageGallery(); + } + }); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + checkCameraAndLoadImage(); } - boolean isCameraButtonSheet = sharedPreferences.getBoolean(SHP_SETTING.KEY_CAMERA_BUTTON_SHEET, true); - if (isCameraButtonSheet && isNewBottomSheet) { + } + + private void checkCameraAndLoadImage() { + boolean isCameraButtonSheet = sharedPreferences.getBoolean(SHP_SETTING.KEY_CAMERA_BUTTON_SHEET, true); + if (isCameraButtonSheet) { try { HelperPermission.getCameraPermission(G.fragmentActivity, new OnGetPermission() { @Override public void Allow() throws IOException { - fastItemAdapter.add(new AdapterCamera("").withIdentifier(99)); - for (int i = 0; i < itemGalleryList.size(); i++) { - fastItemAdapter.add(new AdapterBottomSheet(itemGalleryList.get(i)).withIdentifier(100 + i)); - isPermissionCamera = true; - } + G.handler.post(new Runnable() { + @Override + public void run() { + fastItemAdapter.add(new AdapterCamera("").withIdentifier(99)); + for (int i = 0; i < FragmentEditImage.itemGalleryList.size(); i++) { + fastItemAdapter.add(new AdapterBottomSheet(FragmentEditImage.itemGalleryList.get(i)).withIdentifier(100 + i)); + } + isPermissionCamera = true; + } + }); G.handler.postDelayed(new Runnable() { @Override public void run() { if (isAdded()) { - bottomSheetDialog.show(); + showBottomSheet(); } } }, 100); - } @Override @@ -6660,28 +6936,41 @@ public void deny() { } else { loadImageGallery(); } + } + private void showBottomSheet() { + bottomSheetDialog.show(); + if (FragmentEditImage.textImageList != null && FragmentEditImage.textImageList.size() > 0) { + //send.setText(R.mipmap.send2); + if (send != null) + send.setText(G.fragmentActivity.getResources().getString(R.string.md_send_button)); + if (txtCountItem != null) + txtCountItem.setText("" + FragmentEditImage.textImageList.size() + " " + G.fragmentActivity.getResources().getString(item)); + } else { + //send.setImageResource(R.mipmap.ic_close); + if (send != null) + send.setText(G.fragmentActivity.getResources().getString(R.string.igap_chevron_double_down)); + if (txtCountItem != null) + txtCountItem.setText(G.fragmentActivity.getResources().getString(R.string.navigation_drawer_close)); + } } private void loadImageGallery() { - if (isNewBottomSheet) { - G.handler.post(new Runnable() { - @Override - public void run() { - for (int i = 0; i < itemGalleryList.size(); i++) { - fastItemAdapter.add(new AdapterBottomSheet(itemGalleryList.get(i)).withIdentifier(100 + i)); - } + G.handler.post(new Runnable() { + @Override + public void run() { + for (int i = 0; i < FragmentEditImage.itemGalleryList.size(); i++) { + fastItemAdapter.add(new AdapterBottomSheet(FragmentEditImage.itemGalleryList.get(i)).withIdentifier(100 + i)); } - }); - } + } + }); G.handler.postDelayed(new Runnable() { @Override public void run() { if (isAdded()) { - bottomSheetDialog.show(); - fastItemAdapter.notifyDataSetChanged(); + showBottomSheet(); } } }, 100); @@ -7323,6 +7612,7 @@ private void switchAddItem(ArrayList messageInfos, boolean ad } } else { + /** * don't allow for add lower messageId to bottom of list */ @@ -7334,6 +7624,13 @@ private void switchAddItem(ArrayList messageInfos, boolean ad continue; } + + if (lastMessageId == parseLong(messageInfo.messageID)) { + continue; + } else { + lastMessageId = parseLong(messageInfo.messageID); + } + if (messageInfo.showTime) { if (mAdapter.getItemCount() > 0) { if (mAdapter.getAdapterItem(mAdapter.getItemCount() - 1).mMessage != null && RealmRoomMessage.isTimeDayDifferent(messageInfo.time, mAdapter.getAdapterItem(mAdapter.getItemCount() - 1).mMessage.time)) { @@ -7353,6 +7650,13 @@ private void switchAddItem(ArrayList messageInfos, boolean ad mAdapter.add(index, new TextItem(getRealmChat(), chatType, this).setMessage(messageInfo).withIdentifier(identifier)); } break; + case WALLET: + if (!addTop) { + mAdapter.add(new LogWallet(getRealmChat(), chatType, this).setMessage(messageInfo).withIdentifier(identifier)); + } else { + mAdapter.add(index, new LogWallet(getRealmChat(), chatType, this).setMessage(messageInfo).withIdentifier(identifier)); + } + break; case IMAGE: if (!addTop) { mAdapter.add(new ImageItem(getRealmChat(), chatType, this).setMessage(messageInfo).withIdentifier(identifier)); @@ -7467,8 +7771,8 @@ private void switchAddItem(ArrayList messageInfos, boolean ad private long gapMessageIdDown; // messageId that maybe lost in local private long reachMessageIdUp; // messageId that will be checked after getHistory for detect reached to that or no private long reachMessageIdDown; // messageId that will be checked after getHistory for detect reached to that or no - private long startFutureMessageIdUp; // for get history from local or online in next step use from this param, ( hint : don't use from adapter items, because maybe this item was deleted and in this state messageId for get history won't be detected. - private long startFutureMessageIdDown; // for get history from local or online in next step use from this param, ( hint : don't use from adapter items, because maybe this item was deleted and in this state messageId for get history won't be detected. + private long startFutureMessageIdUp; // for get history from local or online in next step use from this param, ( hint : don't use from adapter items, because maybe this item was deleted and in this changeState messageId for get history won't be detected. + private long startFutureMessageIdDown; // for get history from local or online in next step use from this param, ( hint : don't use from adapter items, because maybe this item was deleted and in this changeState messageId for get history won't be detected. private long progressIdentifierUp = 0; // store identifier for Up progress item and use it if progress not removed from view after check 'instanceOf' in 'progressItem' method private long progressIdentifierDown = 0; // store identifier for Down progress item and use it if progress not removed from view after check 'instanceOf' in 'progressItem' method private int firstVisiblePosition; // difference between start of adapter item and items that Showing. @@ -7477,6 +7781,9 @@ private void switchAddItem(ArrayList messageInfos, boolean ad private int totalItemCount; // all item in recycler view private int scrollEnd = 80; // (hint: It should be less than MessageLoader.LOCAL_LIMIT ) to determine the limits to get to the bottom or top of the list + /** + * manage save changeState , unread message , load from local or need get message from server and finally load message + */ private void getMessages() { //+Realm realm = Realm.getDefaultInstance(); @@ -7541,7 +7848,7 @@ private void getMessages() { if (direction == DOWN) { resultsUp = getRealmChat().where(RealmRoomMessage.class).equalTo(RealmRoomMessageFields.ROOM_ID, mRoomId).lessThanOrEqualTo(RealmRoomMessageFields.MESSAGE_ID, fetchMessageId).notEqualTo(RealmRoomMessageFields.CREATE_TIME, 0).equalTo(RealmRoomMessageFields.DELETED, false).equalTo(RealmRoomMessageFields.SHOW_MESSAGE, true).findAll().sort(RealmRoomMessageFields.CREATE_TIME, Sort.DESCENDING); /** - * if for UP state client have message detect gap otherwise try for get online message + * if for UP changeState client have message detect gap otherwise try for get online message * because maybe client have message but not exist in Realm yet */ if (resultsUp.size() > 1) { @@ -7613,7 +7920,7 @@ private void getMessages() { } else { /** send request to server for get message. * if direction is DOWN check again realmRoomMessage for detection - * that exist any message without checking deleted state and if + * that exist any message without checking deleted changeState and if * exist use from that messageId instead of zero for getOnlineMessage */ long oldMessageId = 0; @@ -7675,6 +7982,16 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { //realm.close(); } + /** + * first set gap for room message for correctly load message and after than call {@link #getMessages()} + * + * @param messageId set gap for this message id + */ + private void setGapAndGetMessage(long messageId) { + RealmRoomMessage.setGap(messageId); + getMessages(); + } + /** * manage load message from local or from server(online) */ @@ -7749,7 +8066,7 @@ public void run() { } else if (gapMessageId > 0) { /** * detect old messageId that should get history from server with that - * (( hint : in scroll state never should get online message with messageId = 0 + * (( hint : in scroll changeState never should get online message with messageId = 0 * in some cases maybe startFutureMessageIdUp Equal to zero , so i used from this if.)) */ if (startFutureMessageId != 0) { @@ -7854,7 +8171,7 @@ public void onMessage(final long roomId, long startMessageId, long endMessageId, gapDetection(realmRoomMessages, direction); } else if ((direction == UP && isReachedToTopView()) || direction == DOWN && isReachedToBottomView()) { /** - * check this state because if user is near to top view and not scroll get top message from server + * check this changeState because if user is near to top view and not scroll get top message from server */ //getOnlineMessage(startFutureMessageId, directionEnum); } @@ -8002,7 +8319,7 @@ private boolean hasUnread() { } /** - * check that this room has saved state or no + * check that this room has saved changeState or no */ private boolean hasSavedState() { return savedScrollMessageId > 0; @@ -8016,9 +8333,9 @@ private long getSavedState() { } /** - * manage progress state in adapter + * manage progress changeState in adapter * - * @param progressState SHOW or HIDE state detect with enum + * @param progressState SHOW or HIDE changeState detect with enum * @param direction define direction for show progress in UP or DOWN */ private void progressItem(final ProgressState progressState, final ProtoClientGetRoomHistory.ClientGetRoomHistory.Direction direction) { @@ -8113,6 +8430,7 @@ private void resetMessagingValue() { visibleItemCount = 0; totalItemCount = 0; unreadCount = 0; + biggestMessageId = 0; } @Override @@ -8471,5 +8789,20 @@ public void run() { } + private void showPaymentDialog() { + RealmRoom realmRoom = getRealmChat().where(RealmRoom.class).equalTo(RealmRoomFields.ID, mRoomId).findFirst(); + if (realmRoom != null) { + chatType = realmRoom.getType(); + if (chatType == CHAT) { + chatPeerId = realmRoom.getChatRoom().getPeerId(); + if (imvUserPicture != null && txtName != null) { + paymentDialog = PaymentFragment.newInstance(chatPeerId, imvUserPicture.getDrawable(), txtName.getText().toString()); +// paymentDialog.show(getFragmentManager(), "payment_dialog"); + new HelperFragment(paymentDialog).setTag("PaymentFragment").setReplace(false).load(); + } + } + } + + } } diff --git a/app/src/main/java/net/iGap/fragments/FragmentContactsProfile.java b/app/src/main/java/net/iGap/fragments/FragmentContactsProfile.java index 6629353..50bf0f2 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentContactsProfile.java +++ b/app/src/main/java/net/iGap/fragments/FragmentContactsProfile.java @@ -14,8 +14,10 @@ import android.content.ClipboardManager; import android.content.ContentProviderOperation; import android.content.Intent; +import android.content.res.ColorStateList; import android.database.Cursor; import android.databinding.DataBindingUtil; +import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -137,6 +139,9 @@ public void onComplete(RippleView rippleView) { } }); + fragmentContactsProfileBinding.chiFabSetPic.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom))); + fragmentContactsProfileBinding.chiFabSetPic.setColorFilter(Color.WHITE); + fragmentContactsProfileBinding.chiFabSetPic.setOnClickListener(new View.OnClickListener() { //fab button @Override public void onClick(View view) { @@ -263,7 +268,7 @@ public void onClick(View view) { final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.pu_nikname_profileUser)) .positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)) .customView(layoutNickname, true) - .widgetColor(G.context.getResources().getColor(R.color.toolbar_background)) + .widgetColor(Color.parseColor(G.appBarColor)) .negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)) .build(); @@ -274,7 +279,7 @@ public void onClick(View view) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewFirstName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } @@ -285,7 +290,7 @@ public void onFocusChange(View view, boolean b) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewLastName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } diff --git a/app/src/main/java/net/iGap/fragments/FragmentEditImage.java b/app/src/main/java/net/iGap/fragments/FragmentEditImage.java index 4756fe5..6a29b35 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentEditImage.java +++ b/app/src/main/java/net/iGap/fragments/FragmentEditImage.java @@ -2,6 +2,7 @@ import android.content.Intent; +import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -9,14 +10,20 @@ import android.support.annotation.StringRes; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; -import android.util.Log; +import android.support.v4.view.PagerAdapter; +import android.support.v4.view.ViewPager; +import android.text.Editable; +import android.text.TextWatcher; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; +import com.hanks.library.AnimateCheckBox; import com.theartofdev.edmodo.cropper.CropImage; import com.theartofdev.edmodo.cropper.CropImageView; import com.vanniktech.emoji.EmojiPopup; @@ -29,17 +36,22 @@ import net.iGap.G; import net.iGap.R; +import net.iGap.Theme; import net.iGap.fragments.filterImage.FragmentFilterImage; import net.iGap.helper.HelperFragment; +import net.iGap.helper.HelperPermission; import net.iGap.module.AndroidUtils; import net.iGap.module.AttachFile; import net.iGap.module.EmojiEditTextE; import net.iGap.module.MaterialDesignTextView; +import net.iGap.module.structs.StructBottomSheet; import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; import static android.app.Activity.RESULT_OK; -import static net.iGap.R.id.ac_ll_parent; +import static net.iGap.module.AndroidUtils.closeKeyboard; import static net.iGap.module.AndroidUtils.suitablePath; /** @@ -50,19 +62,35 @@ public class FragmentEditImage extends BaseFragment { private final static String PATH = "PATH"; private final static String ISCHAT = "ISCHAT"; private final static String ISNICKNAMEPAGE = "ISNICKNAMEPAGE"; - private String path; - private ImageView imgEditImage; + private final static String SELECT_POSITION = "SLECT_POSITION"; + // private String path; + private int selectPosition = 0; + // private ImageView imgEditImage; + private ViewPager viewPager; + private AdapterViewPager mAdapter; + private TextView txtEditImage; public static UpdateImage updateImage; private EmojiEditTextE edtChat; + private TextView iconOk; + private ViewGroup layoutCaption; + private MaterialDesignTextView txtSet; + private MaterialDesignTextView imvSendButton; + private ViewGroup rootSend; private MaterialDesignTextView imvSmileButton; private boolean isEmojiSHow = false; private boolean initEmoji = false; private EmojiPopup emojiPopup; private String SAMPLE_CROPPED_IMAGE_NAME; private boolean isChatPage = true; + private boolean isMultiItem = true; private boolean isNicknamePage = false; public static CompleteEditImage completeEditImage; private int num = 0; + private TextView txtCountImage; + private ArrayList listPathString = new ArrayList<>(); + private AnimateCheckBox checkBox; + public static HashMap textImageList = new HashMap<>(); + public static ArrayList itemGalleryList = new ArrayList(); public FragmentEditImage() { // Required empty public constructor @@ -76,11 +104,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, return inflater.inflate(R.layout.fragment_edit_image, container, false); } - public static FragmentEditImage newInstance(String path, boolean isChatPage, boolean isNicknamePage) { + public static FragmentEditImage newInstance(String path, boolean isChatPage, boolean isNicknamePage, int selectPosition) { Bundle args = new Bundle(); args.putString(PATH, path); args.putBoolean(ISCHAT, isChatPage); args.putBoolean(ISNICKNAMEPAGE, isNicknamePage); + args.putInt(SELECT_POSITION, selectPosition); FragmentEditImage fragment = new FragmentEditImage(); fragment.setArguments(args); return fragment; @@ -91,43 +120,70 @@ public static FragmentEditImage newInstance(String path, boolean isChatPage, boo public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - Bundle bundle = getArguments(); - if (bundle != null) { - path = bundle.getString(PATH); - isChatPage = bundle.getBoolean(ISCHAT); - isNicknamePage = bundle.getBoolean(ISNICKNAMEPAGE); - } + initView(view); - if (path == null) { + if (itemGalleryList == null || itemGalleryList.size() == 0) { if (G.fragmentManager != null) { G.fragmentManager.beginTransaction().remove(FragmentEditImage.this).commit(); } return; } - imgEditImage = (ImageView) view.findViewById(R.id.imgEditImage); + if (isChatPage) { - TextView txtEditImage = (TextView) view.findViewById(R.id.txtEditImage); - txtEditImage.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AndroidUtils.closeKeyboard(v); - if (!isNicknamePage) { - new HelperFragment(FragmentFilterImage.newInstance(path)).setReplace(false).load(); - } else { - FragmentFilterImage fragment = FragmentFilterImage.newInstance(path); - G.fragmentActivity.getSupportFragmentManager().beginTransaction().add(R.id.ar_layout_root, fragment).setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_exit_in_right, R.anim.slide_exit_out_left).commitAllowingStateLoss(); - } + layoutCaption.setVisibility(View.VISIBLE); + imvSendButton.setVisibility(View.VISIBLE); + txtSet.setVisibility(View.GONE); + checkBox.setVisibility(View.VISIBLE); + if (textImageList.size() > 0) { + txtCountImage.setVisibility(View.VISIBLE); + txtCountImage.setText(textImageList.size() + ""); + } else { + txtCountImage.setVisibility(View.GONE); } - }); - G.imageLoader.displayImage(suitablePath(path), imgEditImage); + if (itemGalleryList != null && itemGalleryList.size() == 1) { + checkBox.setVisibility(View.GONE); + txtCountImage.setVisibility(View.GONE); + isMultiItem = false; + + } + } else { + txtSet.setVisibility(View.VISIBLE); + layoutCaption.setVisibility(View.GONE); + imvSendButton.setVisibility(View.GONE); + checkBox.setVisibility(View.GONE); + txtCountImage.setVisibility(View.GONE); + isMultiItem = false; + } + + /** + * + * check list size for show number of select item + * + */ + + + setViewPager(); + setCheckBoxItem(); + messageBox(view); + + +// G.imageLoader.displayImage(suitablePath(path), imgEditImage); updateImage = new UpdateImage() { @Override public void result(String pathImageFilter) { - path = pathImageFilter; - G.imageLoader.displayImage(suitablePath(path), imgEditImage); + serCropAndFilterImage(pathImageFilter); + G.handler.post(new Runnable() { + @Override + public void run() { + mAdapter.notifyDataSetChanged(); + } + }); + + +// G.imageLoader.displayImage(suitablePath(path), imgEditImage); } }; @@ -143,51 +199,120 @@ public void onClick(View v) { }); view.findViewById(R.id.pu_txt_crop).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + goToCropPage(v); + } + + }); + + + txtSet.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if (completeEditImage != null) { + completeEditImage.result(itemGalleryList.get(0).getPath(), "", null); + } + + new HelperFragment(FragmentEditImage.this).remove(); + AndroidUtils.closeKeyboard(v); + } + }); + + imvSendButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new HelperFragment(FragmentEditImage.this).remove(); + + if (textImageList.size() == 0) { + setValueCheckBox(viewPager.getCurrentItem()); + } + + completeEditImage.result("", edtChat.getText().toString(), textImageList); + AndroidUtils.closeKeyboard(v); + } + }); + + isSoftKeyboardOpenOrNot(view); + } + + private void isSoftKeyboardOpenOrNot(final View view) { + + view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + int heightDiff = view.getRootView().getHeight() - view.getHeight(); + if (heightDiff > AndroidUtils.dpToPx(G.fragmentActivity, 200)) { // if more than 200 dp, it's probably a keyboard... + // ... do something here + rootSend.setVisibility(View.GONE); + } else { + rootSend.setVisibility(View.VISIBLE); + } + } + }); + + } + + private void messageBox(final View view) { + if (textImageList.containsKey(itemGalleryList.get((itemGalleryList.size() - selectPosition - 1)).path)) { + edtChat.setText(textImageList.get(itemGalleryList.get((itemGalleryList.size() - selectPosition - 1)).path).getText()); + } else { + edtChat.setText(""); + } + + txtEditImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AndroidUtils.closeKeyboard(v); - String newPath = "file://" + path; - String fileNameWithOutExt = path.substring(path.lastIndexOf("/")); - String extension = path.substring(path.lastIndexOf(".")); - SAMPLE_CROPPED_IMAGE_NAME = fileNameWithOutExt.substring(0, fileNameWithOutExt.lastIndexOf(".")) + num + extension; - num++; - Uri uri = Uri.parse(newPath); - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { - UCrop.Options options = new UCrop.Options(); - options.setStatusBarColor(ContextCompat.getColor(G.context, R.color.black)); - options.setToolbarColor(ContextCompat.getColor(G.context, R.color.black)); - options.setCompressionQuality(80); - options.setFreeStyleCropEnabled(true); - - UCrop.of(uri, Uri.fromFile(new File(G.DIR_IMAGES, SAMPLE_CROPPED_IMAGE_NAME))) - .withOptions(options) - .useSourceImageAspectRatio() - .start(G.context, FragmentEditImage.this); + if (!isNicknamePage) { + new HelperFragment(FragmentFilterImage.newInstance(itemGalleryList.get(viewPager.getCurrentItem()).path)).setReplace(false).load(); } else { - CropImage.activity(uri) - .setGuidelines(CropImageView.Guidelines.ON) - .setMinCropResultSize(120, 120) - .setAutoZoomEnabled(false) - .setInitialCropWindowPaddingRatio(.08f) // padding window from all - .setBorderCornerLength(50) - .setBorderCornerOffset(0) - .setAllowCounterRotation(true) - .setBorderCornerThickness(8.0f) - .setShowCropOverlay(true) - .setAspectRatio(1, 1) - .setFixAspectRatio(false) - .setBorderCornerColor(getResources().getColor(R.color.whit_background)) - .setBackgroundColor(getResources().getColor(R.color.ou_background_crop)) - .setScaleType(CropImageView.ScaleType.FIT_CENTER) - .start(G.fragmentActivity, FragmentEditImage.this); + FragmentFilterImage fragment = FragmentFilterImage.newInstance(itemGalleryList.get(viewPager.getCurrentItem()).path); + G.fragmentActivity.getSupportFragmentManager().beginTransaction().add(R.id.ar_layout_root, fragment).setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_exit_in_right, R.anim.slide_exit_out_left).commitAllowingStateLoss(); } + } + }); + + + /** + * + * get message for each item + * + */ + + iconOk.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + String path = itemGalleryList.get(viewPager.getCurrentItem()).path; + String message = edtChat.getText().toString(); + + itemGalleryList.get(viewPager.getCurrentItem()).setSelected(false); + checkBox.setChecked(true); + checkBox.setUnCheckColor(G.context.getResources().getColor(R.color.green)); + + StructBottomSheet item = new StructBottomSheet(); + item.setPath(path); + item.setText(message); + item.setId(itemGalleryList.get(viewPager.getCurrentItem()).getId()); + + textImageList.put(path, item); +// FragmentChat.listPathString.add(itemGalleryList.get(((itemGalleryList.size() - selectPosition) - 1)).path); + if (textImageList.size() > 0 && isMultiItem) { + txtCountImage.setVisibility(View.VISIBLE); + txtCountImage.setText(textImageList.size() + ""); + } else { + txtCountImage.setVisibility(View.GONE); + } + closeKeyboard(v); + v.setVisibility(View.GONE); } }); - imvSmileButton = (MaterialDesignTextView) view.findViewById(R.id.chl_imv_smile_button); - edtChat = (EmojiEditTextE) view.findViewById(R.id.chl_edt_chat); edtChat.requestFocus(); edtChat.setOnClickListener(new View.OnClickListener() { @@ -200,6 +325,31 @@ public void onClick(View v) { } }); + edtChat.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + String oldPath = ""; + if (textImageList.containsKey(itemGalleryList.get(viewPager.getCurrentItem()).path)) { + oldPath = textImageList.get(itemGalleryList.get(viewPager.getCurrentItem()).path).getText(); + } + if (!oldPath.equals(s.toString())) { + iconOk.setVisibility(View.VISIBLE); + } else { + iconOk.setVisibility(View.GONE); + } + } + }); + imvSmileButton.setOnClickListener(new View.OnClickListener() { @@ -214,61 +364,83 @@ public void onClick(View v) { } }); - ViewGroup layoutCaption = view.findViewById(R.id.layout_caption); - MaterialDesignTextView txtSet = view.findViewById(R.id.txtSet); - MaterialDesignTextView imvSendButton = (MaterialDesignTextView) view.findViewById(R.id.pu_txt_sendImage); + } - if (isChatPage) { - layoutCaption.setVisibility(View.VISIBLE); - imvSendButton.setVisibility(View.VISIBLE); - txtSet.setVisibility(View.GONE); + private void setCheckBoxItem() { + checkBox.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (isMultiItem) setValueCheckBox(viewPager.getCurrentItem()); + } + }); + + if (itemGalleryList.get(viewPager.getCurrentItem()).isSelected) { + checkBox.setChecked(false); + checkBox.setUnCheckColor(G.context.getResources().getColor(R.color.transparent)); } else { - txtSet.setVisibility(View.VISIBLE); - layoutCaption.setVisibility(View.GONE); - imvSendButton.setVisibility(View.GONE); + checkBox.setChecked(true); + checkBox.setUnCheckColor(G.context.getResources().getColor(R.color.green)); } - txtSet.setOnClickListener(new View.OnClickListener() { + } + + private void setViewPager() { + + mAdapter = new AdapterViewPager(itemGalleryList); + viewPager.setAdapter(mAdapter); + + viewPager.setCurrentItem((itemGalleryList.size() - selectPosition) - 1); + + + viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override - public void onClick(View v) { + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - completeEditImage.result(path, ""); + } - new HelperFragment(FragmentEditImage.this).remove(); - AndroidUtils.closeKeyboard(v); + @Override + public void onPageSelected(int position) { + if (itemGalleryList.get(position).isSelected) { + checkBox.setChecked(false); + checkBox.setUnCheckColor(G.context.getResources().getColor(R.color.transparent)); + } else { + checkBox.setChecked(true); + checkBox.setUnCheckColor(G.context.getResources().getColor(R.color.green)); + } + if (textImageList.containsKey(itemGalleryList.get(position).path)) { + edtChat.setText(textImageList.get(itemGalleryList.get(position).path).getText()); + } else { + edtChat.setText(""); + } + iconOk.setVisibility(View.GONE); } - }); - imvSendButton.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { - new HelperFragment(FragmentEditImage.this).remove(); - completeEditImage.result(path, edtChat.getText().toString()); - AndroidUtils.closeKeyboard(v); + public void onPageScrollStateChanged(int state) { + } }); - } - @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); + String path; if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) { final Uri resultUri = UCrop.getOutput(data); path = AttachFile.getFilePathFromUri(resultUri); -// G.imageLoader.displayImage(path, imgEditImage); - imgEditImage.setImageURI(Uri.parse(path)); + + serCropAndFilterImage(path); + } else if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { // result for crop CropImage.ActivityResult result = CropImage.getActivityResult(data); if (resultCode == RESULT_OK) { - path = result.getUri().getPath(); - imgEditImage.setImageURI(Uri.parse(path)); + serCropAndFilterImage(path); } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { // Exception error = result.getError(); } @@ -280,44 +452,78 @@ public interface UpdateImage { void result(String path); } + + + + + private void setUpEmojiPopup(View view) { - emojiPopup = EmojiPopup.Builder.fromRootView(view.findViewById(ac_ll_parent)).setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() { + switch (G.themeColor) { + case Theme.BLUE_GREY_COMPLETE: + case Theme.INDIGO_COMPLETE: + case Theme.BROWN_COMPLETE: + case Theme.GREY_COMPLETE: + case Theme.TEAL_COMPLETE: + case Theme.DARK: - @Override - public void onEmojiBackspaceClick(View v) { + setEmojiColor(view,G.backgroundTheme_2, G.textTitleTheme, G.textTitleTheme); + break; + default: + setEmojiColor(view,"#eceff1", "#61000000", "#61000000"); - } - }).setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() { - @Override - public void onEmojiPopupShown() { - changeEmojiButtonImageResource(R.string.md_black_keyboard_with_white_keys); - isEmojiSHow = true; - } - }).setOnSoftKeyboardOpenListener(new OnSoftKeyboardOpenListener() { - @Override - public void onKeyboardOpen(final int keyBoardHeight) { - } - }).setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() { - @Override - public void onEmojiPopupDismiss() { - changeEmojiButtonImageResource(R.string.md_emoticon_with_happy_face); - isEmojiSHow = false; - } - }).setOnSoftKeyboardCloseListener(new OnSoftKeyboardCloseListener() { - @Override - public void onKeyboardClose() { - emojiPopup.dismiss(); - } - }).build(edtChat); + } + } + private void setEmojiColor(View view,String BackgroundColor, String iconColor, String dividerColor) { + + emojiPopup = EmojiPopup.Builder.fromRootView(view.findViewById(R.id.ac_ll_parent)) + .setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() { + + @Override + public void onEmojiBackspaceClick(View v) { + + } + }).setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() { + @Override + public void onEmojiPopupShown() { + changeEmojiButtonImageResource(R.string.md_black_keyboard_with_white_keys); + isEmojiSHow = true; + } + }).setOnSoftKeyboardOpenListener(new OnSoftKeyboardOpenListener() { + @Override + public void onKeyboardOpen(final int keyBoardHeight) { + + } + }).setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() { + @Override + public void onEmojiPopupDismiss() { + changeEmojiButtonImageResource(R.string.md_emoticon_with_happy_face); + isEmojiSHow = false; + } + }).setOnSoftKeyboardCloseListener(new OnSoftKeyboardCloseListener() { + @Override + public void onKeyboardClose() { + emojiPopup.dismiss(); + } + }) + .setBackgroundColor(Color.parseColor(BackgroundColor)) + .setIconColor(Color.parseColor(iconColor)) + .setDividerColor(Color.parseColor(dividerColor)) + .build(edtChat); + + } + + + + private void changeEmojiButtonImageResource(@StringRes int drawableResourceId) { imvSmileButton.setText(drawableResourceId); } public interface CompleteEditImage { - void result(String path, String message); + void result(String path, String message, HashMap textImageList); } @Override @@ -343,4 +549,184 @@ public boolean onKey(View v, int keyCode, KeyEvent event) { } }); } + + private class AdapterViewPager extends PagerAdapter { + + ArrayList itemGalleryList; + + public AdapterViewPager(ArrayList itemGalleryList) { + this.itemGalleryList = itemGalleryList; + } + + @Override + public int getCount() { + return itemGalleryList.size(); + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return view.equals(object); + } + + @Override + public int getItemPosition(Object object) { + return POSITION_NONE; + } + + @Override + public Object instantiateItem(ViewGroup container, final int position) { + + LayoutInflater inflater = LayoutInflater.from(G.fragmentActivity); + ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.adapter_viewpager_edittext, (ViewGroup) container, false); + final ImageView imgPlay = (ImageView) layout.findViewById(R.id.img_editImage); + if (itemGalleryList.get(position).path != null) { + G.imageLoader.displayImage(suitablePath(itemGalleryList.get(position).path), imgPlay); + } + + imgPlay.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (isMultiItem) setValueCheckBox(position); + } + }); + ((ViewGroup) container).addView(layout); + return layout; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + container.removeView((View) object); + } + + } + + private void setValueCheckBox(int position) { + + if (checkBox.isChecked()) { + checkBox.setChecked(false); + checkBox.setUnCheckColor(G.context.getResources().getColor(R.color.transparent)); + itemGalleryList.get(position).setSelected(true); + textImageList.remove(itemGalleryList.get(position).path); + + } else { + checkBox.setChecked(true); + StructBottomSheet item = new StructBottomSheet(); + item.setText(edtChat.getText().toString()); + item.setPath(itemGalleryList.get(position).path); + item.setId(itemGalleryList.get(position).getId()); + textImageList.put(itemGalleryList.get(position).path, item); + checkBox.setUnCheckColor(G.context.getResources().getColor(R.color.green)); + itemGalleryList.get(position).setSelected(false); + } + if (textImageList.size() > 0 && isChatPage) { + txtCountImage.setVisibility(View.VISIBLE); + txtCountImage.setText(textImageList.size() + ""); + } else { + txtCountImage.setVisibility(View.GONE); + } + } + + + private void initView(View view) { + + G.fragmentActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + + Bundle bundle = getArguments(); + if (bundle != null) { +// path = bundle.getString(PATH); + isChatPage = bundle.getBoolean(ISCHAT); + isNicknamePage = bundle.getBoolean(ISNICKNAMEPAGE); + selectPosition = bundle.getInt(SELECT_POSITION); + } + + + layoutCaption = view.findViewById(R.id.layout_caption); + txtSet = view.findViewById(R.id.txtSet); + imvSendButton = (MaterialDesignTextView) view.findViewById(R.id.pu_txt_sendImage); + + //imgEditImage = (ImageView) view.findViewById(R.id.imgEditImage); + iconOk = (TextView) view.findViewById(R.id.chl_imv_ok_message); + rootSend = (ViewGroup) view.findViewById(R.id.pu_layout_cancel_crop); + txtEditImage = (TextView) view.findViewById(R.id.txtEditImage); + edtChat = (EmojiEditTextE) view.findViewById(R.id.chl_edt_chat); + txtCountImage = view.findViewById(R.id.stfaq_txt_countImageEditText); + viewPager = view.findViewById(R.id.viewPagerEditText); + checkBox = (AnimateCheckBox) view.findViewById(R.id.checkBox_editImage); + imvSmileButton = (MaterialDesignTextView) view.findViewById(R.id.chl_imv_smile_button); + } + + private void goToCropPage(View v) { + AndroidUtils.closeKeyboard(v); + String newPath = "file://" + itemGalleryList.get(viewPager.getCurrentItem()).path; + String fileNameWithOutExt = newPath.substring(newPath.lastIndexOf("/")); + String extension = newPath.substring(newPath.lastIndexOf(".")); + SAMPLE_CROPPED_IMAGE_NAME = fileNameWithOutExt.substring(0, fileNameWithOutExt.lastIndexOf(".")) + num + extension; + num++; + Uri uri = Uri.parse(newPath); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { + UCrop.Options options = new UCrop.Options(); + options.setStatusBarColor(ContextCompat.getColor(G.context, R.color.black)); + options.setToolbarColor(ContextCompat.getColor(G.context, R.color.black)); + options.setCompressionQuality(80); + options.setFreeStyleCropEnabled(true); + + UCrop.of(uri, Uri.fromFile(new File(G.DIR_IMAGES, SAMPLE_CROPPED_IMAGE_NAME))) + .withOptions(options) + .useSourceImageAspectRatio() + .start(G.context, FragmentEditImage.this); + } else { + CropImage.activity(uri) + .setGuidelines(CropImageView.Guidelines.ON) + .setMinCropResultSize(120, 120) + .setAutoZoomEnabled(false) + .setInitialCropWindowPaddingRatio(.08f) // padding window from all + .setBorderCornerLength(50) + .setBorderCornerOffset(0) + .setAllowCounterRotation(true) + .setBorderCornerThickness(8.0f) + .setShowCropOverlay(true) + .setAspectRatio(1, 1) + .setFixAspectRatio(false) + .setBorderCornerColor(getResources().getColor(R.color.whit_background)) + .setBackgroundColor(getResources().getColor(R.color.ou_background_crop)) + .setScaleType(CropImageView.ScaleType.FIT_CENTER) + .start(G.fragmentActivity, FragmentEditImage.this); + } + } + + public static ArrayList insertItemList(String path, boolean isSelected) { + + if (itemGalleryList == null) { + itemGalleryList = new ArrayList<>(); + } + + if (!HelperPermission.grantedUseStorage()) { + return itemGalleryList; + } + StructBottomSheet item = new StructBottomSheet(); + item.setId(itemGalleryList.size()); + item.setPath(path); + item.setText(""); + item.isSelected = isSelected; + itemGalleryList.add(0, item); + textImageList.put(path, item); + + return itemGalleryList; + } + + private void serCropAndFilterImage(String path) { + + int po = (viewPager.getCurrentItem()); + + if (textImageList.containsKey(itemGalleryList.get(po).getPath())) { + textImageList.get(itemGalleryList.get(po).getPath()).setPath(path); + } + itemGalleryList.get(viewPager.getCurrentItem()).setPath(path); + + + mAdapter.notifyDataSetChanged(); + + + } + } diff --git a/app/src/main/java/net/iGap/fragments/FragmentExplorer.java b/app/src/main/java/net/iGap/fragments/FragmentExplorer.java index 47a1cad..4bc84e2 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentExplorer.java +++ b/app/src/main/java/net/iGap/fragments/FragmentExplorer.java @@ -37,8 +37,6 @@ import java.util.ArrayList; import java.util.List; -import static net.iGap.G.IGAP; - public class FragmentExplorer extends BaseFragment { String nextnode; @@ -189,14 +187,13 @@ void firstfill() { } if (!G.DIR_SDCARD_EXTERNAL.equals("")) { - String sdPath = G.DIR_SDCARD_EXTERNAL + IGAP; - if (new File(sdPath).exists()) { + if (new File(G.DIR_SDCARD_EXTERNAL).exists()) { x = new StructExplorerItem(); x.name = "iGap SdCard"; x.image = R.mipmap.actionbar_icon_myfiles; - x.path = sdPath + "/"; + x.path = G.DIR_SDCARD_EXTERNAL + "/"; item.add(x); - node.add(sdPath + "/"); + node.add(G.DIR_SDCARD_EXTERNAL + "/"); rootcount++; } } diff --git a/app/src/main/java/net/iGap/fragments/FragmentFinancialServices.java b/app/src/main/java/net/iGap/fragments/FragmentFinancialServices.java new file mode 100644 index 0000000..e831f67 --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentFinancialServices.java @@ -0,0 +1,85 @@ +package net.iGap.fragments; + +import android.content.Intent; +import android.graphics.Color; +import android.net.Uri; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.libs.rippleeffect.RippleView; + +public class FragmentFinancialServices extends BaseFragment { + + public static final String OPEN_IN_FRAGMENT_MAIN = "OPEN_IN_FRAGMENT_MAIN"; + boolean openInMain = false; + + public static FragmentFinancialServices newInstance(boolean openInFragmentMain) { + FragmentFinancialServices fragmentFinancialServices = new FragmentFinancialServices(); + Bundle bundle = new Bundle(); + bundle.putBoolean(OPEN_IN_FRAGMENT_MAIN, openInFragmentMain); + fragmentFinancialServices.setArguments(bundle); + return fragmentFinancialServices; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_financial_services, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + openInMain = getArguments().getBoolean(OPEN_IN_FRAGMENT_MAIN); + + view.findViewById(R.id.fc_layot_title).setBackgroundColor(Color.parseColor(G.appBarColor)); //set title bar color + + + RippleView rippleBack = (RippleView) view.findViewById(R.id.fc_call_ripple_txtBack); + rippleBack.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() { + @Override + public void onComplete(RippleView rippleView) { + G.fragmentActivity.onBackPressed(); + } + }); + + + TextView txtTop = view.findViewById(R.id.top); + txtTop.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String url = "https://taps.io/get-top"; + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + startActivity(i); + } + }); + + + TextView txtPagear = view.findViewById(R.id.paygear); + txtPagear.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String url = "https://taps.io/get-paygear"; + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + startActivity(i); + } + }); + + + if (openInMain) { + view.findViewById(R.id.fc_layot_title).setVisibility(View.GONE); + + } + + } + +} diff --git a/app/src/main/java/net/iGap/fragments/FragmentGroupProfile.java b/app/src/main/java/net/iGap/fragments/FragmentGroupProfile.java index 955c3fc..eaf3a62 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentGroupProfile.java +++ b/app/src/main/java/net/iGap/fragments/FragmentGroupProfile.java @@ -3,7 +3,9 @@ import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.ColorStateList; import android.databinding.DataBindingUtil; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; @@ -47,6 +49,7 @@ import net.iGap.module.FileUploadStructure; import net.iGap.module.SUID; import net.iGap.module.enums.GroupChatRole; +import net.iGap.module.structs.StructBottomSheet; import net.iGap.proto.ProtoGlobal; import net.iGap.request.RequestGroupAvatarAdd; import net.iGap.request.RequestGroupKickAdmin; @@ -55,6 +58,7 @@ import net.iGap.viewmodel.FragmentGroupProfileViewModel; import java.io.IOException; +import java.util.HashMap; /* * This is the source code of iGap for Android @@ -120,7 +124,7 @@ public void onBack() { FragmentEditImage.completeEditImage = new FragmentEditImage.CompleteEditImage() { @Override - public void result(String path, String message) { + public void result(String path, String message, HashMap textImageList) { pathSaveImage = null; pathSaveImage = path; long avatarId = SUID.id().get(); @@ -166,14 +170,21 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { String filePath = null; long avatarId = SUID.id().get(); + + if (FragmentEditImage.textImageList != null) FragmentEditImage.textImageList.clear(); + if (FragmentEditImage.itemGalleryList != null) + FragmentEditImage.itemGalleryList.clear(); + switch (requestCode) { case AttachFile.request_code_TAKE_PICTURE: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - new HelperFragment(FragmentEditImage.newInstance(AttachFile.mCurrentPhotoPath, false, false)).setReplace(false).load(); + FragmentEditImage.insertItemList(AttachFile.mCurrentPhotoPath, false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); } else { - new HelperFragment(FragmentEditImage.newInstance(AttachFile.imagePath, false, false)).setReplace(false).load(); + FragmentEditImage.insertItemList(AttachFile.imagePath, false); + new HelperFragment(FragmentEditImage.newInstance(AttachFile.imagePath, false, false, 0)).setReplace(false).load(); } break; @@ -181,7 +192,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (data.getData() == null) { return; } - new HelperFragment(FragmentEditImage.newInstance(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false, false)).setReplace(false).load(); + FragmentEditImage.insertItemList(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); break; } @@ -231,6 +243,9 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { }); FloatingActionButton fab = fragmentGroupProfileBinding.agpFabSetPic; + fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom))); + fab.setColorFilter(Color.WHITE); + if (fragmentGroupProfileViewModel.role == GroupChatRole.OWNER || fragmentGroupProfileViewModel.role == GroupChatRole.ADMIN) { fab.setVisibility(View.VISIBLE); // diff --git a/app/src/main/java/net/iGap/fragments/FragmentIgapSearch.java b/app/src/main/java/net/iGap/fragments/FragmentIgapSearch.java index 064e245..0ae53c3 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentIgapSearch.java +++ b/app/src/main/java/net/iGap/fragments/FragmentIgapSearch.java @@ -12,6 +12,7 @@ import android.content.Context; import android.graphics.Color; +import android.graphics.PorterDuff; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.widget.ContentLoadingProgressBar; @@ -50,6 +51,8 @@ import net.iGap.realm.RealmRoomFields; import net.iGap.request.RequestClientSearchUsername; +import org.paygear.wallet.WalletActivity; + import java.util.ArrayList; import java.util.List; @@ -110,7 +113,7 @@ public void run() { }, 150); loadingProgressBar = (ContentLoadingProgressBar) view.findViewById(R.id.sfl_progress_loading); - loadingProgressBar.getIndeterminateDrawable().setColorFilter(G.context.getResources().getColor(R.color.toolbar_background), android.graphics.PorterDuff.Mode.MULTIPLY); + loadingProgressBar.getIndeterminateDrawable().setColorFilter(Color.parseColor(G.progressColor), PorterDuff.Mode.SRC_IN); edtSearch = (EditText) view.findViewById(R.id.sfl_edt_search); diff --git a/app/src/main/java/net/iGap/fragments/FragmentMain.java b/app/src/main/java/net/iGap/fragments/FragmentMain.java index c9ffdc8..4854033 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentMain.java +++ b/app/src/main/java/net/iGap/fragments/FragmentMain.java @@ -116,6 +116,7 @@ public class FragmentMain extends BaseFragment implements OnComplete, OnSetActio private RecyclerView mRecyclerView; private long tagId; private Realm realmFragmentMain; + private RecyclerView.OnScrollListener onScrollListener; public static FragmentMain newInstance(MainType mainType) { Bundle bundle = new Bundle(); @@ -209,6 +210,34 @@ private void initRecycleView(View view) { final RoomAdapter roomsAdapter = new RoomAdapter(results, this); + + if (!G.multiTab) { + onScrollListener = new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + if (isThereAnyMoreItemToLoad) { + if (!isSendRequestForLoading && mOffset > 0) { + int lastVisiblePosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition(); + if (lastVisiblePosition + 10 >= mOffset) { + isSendRequestForLoading = true; + new RequestClientGetRoomList().clientGetRoomList(mOffset, Config.LIMIT_LOAD_ROOM, tagId + ""); + G.handler.post(new Runnable() { + @Override + public void run() { + progressBar.setVisibility(View.VISIBLE); + } + }); + } + } + } else { + mRecyclerView.removeOnScrollListener(onScrollListener); + } + } + }; + mRecyclerView.addOnScrollListener(onScrollListener); + } + mRecyclerView.setAdapter(roomsAdapter); if (roomAdapterHashMap == null) { @@ -322,6 +351,7 @@ public void onClientGetRoomList(List roomList, ProtoResponse.R @Override public void onError(int majorCode, int minorCode) { + isSendRequestForLoading = false; G.handler.post(new Runnable() { @Override public void run() { @@ -349,6 +379,7 @@ public void run() { progressBar.setVisibility(View.GONE); firstTimeEnterToApp = false; getChatsList(); + isSendRequestForLoading = false; swipeRefreshLayout.setRefreshing(false);// swipe refresh is complete and gone } }); @@ -450,7 +481,7 @@ private void onClientGetRoomList(List roomList, ProtoResponse. /** * to first enter to app , client first compute clientCondition then * getRoomList and finally send condition that before get clientCondition; - * in else state compute new client condition with latest messaging state + * in else changeState compute new client condition with latest messaging changeState */ if (firstTimeEnterToApp) { firstTimeEnterToApp = false; @@ -484,7 +515,7 @@ public void run() { isSendRequestForLoading = false; - if (isThereAnyMoreItemToLoad) { + if (isThereAnyMoreItemToLoad && G.multiTab) { isSendRequestForLoading = true; new RequestClientGetRoomList().clientGetRoomList(mOffset, Config.LIMIT_LOAD_ROOM, tagId + ""); @@ -1194,7 +1225,12 @@ private void setLastMessage(RealmRoom mInfo, ViewHolder holder, boolean isMyClou holder.lastMessageSender.setVisibility(View.VISIBLE); holder.lastMessageSender.setText(R.string.txt_draft); - holder.lastMessageSender.setTextColor(context.getResources().getColor(R.color.toolbar_background)); + if (G.isDarkTheme) { + holder.lastMessageSender.setTextColor(Color.parseColor(G.textSubTheme)); + } else { + holder.lastMessageSender.setTextColor(Color.parseColor(G.appBarColor)); + } + holder.lastMessageSender.setTypeface(G.typeface_IRANSansMobile); } else { @@ -1255,7 +1291,12 @@ private void setLastMessage(RealmRoom mInfo, ViewHolder holder, boolean isMyClou holder.lastMessageSender.setVisibility(View.VISIBLE); holder.lastMessageSender.setText(lastMessageSender); - holder.lastMessageSender.setTextColor(Color.parseColor("#2bbfbd")); + if (G.isDarkTheme) { + holder.lastMessageSender.setTextColor(Color.parseColor(G.textSubTheme)); + } else { + holder.lastMessageSender.setTextColor(Color.parseColor(G.appBarColor)); + } + } else { holder.lastMessageSender.setVisibility(View.GONE); } @@ -1343,7 +1384,7 @@ private void setAvatar(final RealmRoom mInfo, CircleImageView imageView) { HelperAvatar.getAvatar(idForGetAvatar, avatarType, false, new OnAvatarGet() { @Override public void onAvatarGet(String avatarPath, long idForGetAvatar) { - if (hashMapAvatar.get(idForGetAvatar) != null) { + if (hashMapAvatar.get(idForGetAvatar) != null && avatarPath != null) { G.imageLoader.displayImage(AndroidUtils.suitablePath(avatarPath), hashMapAvatar.get(idForGetAvatar)); } } diff --git a/app/src/main/java/net/iGap/fragments/FragmentMap.java b/app/src/main/java/net/iGap/fragments/FragmentMap.java index 88bd705..8313efd 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentMap.java +++ b/app/src/main/java/net/iGap/fragments/FragmentMap.java @@ -1,31 +1,49 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.fragments; +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Point; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.graphics.drawable.Drawable; +import android.location.Criteria; import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.FloatingActionButton; import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.util.Log; import android.view.Display; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; @@ -38,11 +56,18 @@ import net.iGap.G; import net.iGap.R; +import net.iGap.helper.HelperAvatar; +import net.iGap.helper.HelperCalander; import net.iGap.helper.HelperError; import net.iGap.helper.HelperFragment; import net.iGap.helper.HelperSetAction; import net.iGap.helper.HelperString; +import net.iGap.interfaces.OnAvatarGet; +import net.iGap.module.AndroidUtils; import net.iGap.proto.ProtoGlobal; +import net.iGap.realm.RealmRegisteredInfo; +import net.iGap.realm.RealmRegisteredInfoFields; +import net.iGap.realm.RealmRoom; import java.io.File; import java.io.FileNotFoundException; @@ -50,31 +75,73 @@ import java.io.InputStream; import java.io.OutputStream; +import io.realm.Realm; + import static net.iGap.R.id.mf_fragment_map_view; -public class FragmentMap extends BaseFragment implements OnMapReadyCallback { +public class FragmentMap extends BaseFragment implements OnMapReadyCallback, View.OnClickListener, LocationListener { public static String Latitude = "latitude"; public static String Longitude = "longitude"; public static String PosoitionMode = "positionMode"; + + public static String flagFragmentMap = "FragmentMap"; Marker marker; private GoogleMap mMap; private Double latitude; private Double longitude; private Mode mode; + private TextView accuracy, txtTitle, txtUserName, txtDistance; + private ImageView imgProfile; + + private boolean showGPS = false; + + private RelativeLayout rvSendPosition, rvSeePosition; + private FloatingActionButton fabOpenMap; + private Bundle bundle; + private RelativeLayout rvIcon; + private net.iGap.module.MaterialDesignTextView itemIcon; + private Location location; + + /* Realm realm = Realm.getDefaultInstance(); + ProtoGlobal.Room.Type type= RealmRoom.detectType(mMessage.roomId); + if (type== ProtoGlobal.Room.Type.CHAT|| type== ProtoGlobal.Room.Type.GROUP) + { - public static FragmentMap getInctance(Double latitude, Double longitude, Mode mode) { + + RealmRegisteredInfo realmRegisteredInfo = realm.where(RealmRegisteredInfo.class).equalTo(RealmRegisteredInfoFields.ID,12342).findFirst(); + }else{ + + }*/ + + public static FragmentMap getInctance(Double latitude, Double longitude, Mode mode, int type, long roomId, String senderID) { FragmentMap fragmentMap = new FragmentMap(); Bundle bundle = new Bundle(); + bundle.putInt("type", type); + bundle.putLong("roomId", roomId); + bundle.putString("senderId", senderID); + bundle.putDouble(FragmentMap.Latitude, latitude); bundle.putDouble(FragmentMap.Longitude, longitude); bundle.putSerializable(PosoitionMode, mode); fragmentMap.setArguments(bundle); + return fragmentMap; + } + public static FragmentMap getInctance(Double latitude, Double longitude, Mode mode) { + + FragmentMap fragmentMap = new FragmentMap(); + + Bundle bundle = new Bundle(); + bundle.putDouble(FragmentMap.Latitude, latitude); + bundle.putDouble(FragmentMap.Longitude, longitude); + bundle.putSerializable(PosoitionMode, mode); + + fragmentMap.setArguments(bundle); return fragmentMap; } @@ -85,7 +152,28 @@ public static String saveBitmapToFile(Bitmap bitmap) { try { if (bitmap == null) return result; - String fileName = "location_" + HelperString.getRandomFileName(3) + ".png"; + String fileName = "/location_" + HelperString.getRandomFileName(3) + ".png"; + File file = new File(G.DIR_TEMP, fileName); + + OutputStream fOut = new FileOutputStream(file); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); + + result = file.getPath(); + } catch (FileNotFoundException e) { + + } + + return result; + } + + public String saveMapToFile(Bitmap bitmap) { + + String result = ""; + + try { + if (bitmap == null) return result; + + String fileName = "/location_" + latitude.toString().replace(".", "") + "_" + longitude.toString().replace(".", "") + ".png"; File file = new File(G.DIR_TEMP, fileName); OutputStream fOut = new FileOutputStream(file); @@ -116,18 +204,65 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, public void onViewCreated(View view, @Nullable Bundle saveInctanceState) { super.onViewCreated(view, saveInctanceState); - Bundle bundle = getArguments(); + + /* *//**//* itemIcon = (MaterialDesignTextView) view.findViewById(R.id.mf_icon);*/ + + + rvIcon = (RelativeLayout) view.findViewById(R.id.rv_icon); + + Drawable mDrawableSkip = ContextCompat.getDrawable(getContext(), R.drawable.ic_circle_shape); + if (mDrawableSkip != null) { + mDrawableSkip.setColorFilter(new PorterDuffColorFilter(Color.parseColor(G.appBarColor), PorterDuff.Mode.SRC_IN)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + rvIcon.setBackground(mDrawableSkip); + } + } + + + imgProfile = (ImageView) view.findViewById(R.id.mf_imgProfile); + + rvSendPosition = (RelativeLayout) view.findViewById(R.id.mf_rv_send_position); + rvSeePosition = (RelativeLayout) view.findViewById(R.id.mf_rv_see_position); + + rvSendPosition.setEnabled(false); + + accuracy = (TextView) view.findViewById(R.id.mf_txt_accuracy); + accuracy.setText(getResources().getString(R.string.get_location_data)); + + + txtTitle = (TextView) view.findViewById(R.id.mf_txt_message); + + txtUserName = (TextView) view.findViewById(R.id.mf_txt_userName); + txtDistance = (TextView) view.findViewById(R.id.mf_txt_distance); + + txtDistance.setText(getResources().getString(R.string.calculation)); + + txtUserName.setTextColor(Color.parseColor(G.appBarColor)); + + accuracy.setTextColor(Color.parseColor(G.appBarColor)); + txtDistance.setTextColor(Color.parseColor(G.appBarColor)); + + + //rvSendPosition.setBackgroundColor(Color.parseColor(G.appBarColor)); + txtTitle.setTextColor(Color.parseColor(G.appBarColor)); + + fabOpenMap = (FloatingActionButton) view.findViewById(R.id.mf_fab_openMap); + fabOpenMap.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom))); + fabOpenMap.setColorFilter(Color.WHITE); + + bundle = getArguments(); if (bundle != null) { latitude = bundle.getDouble(FragmentMap.Latitude); longitude = bundle.getDouble(FragmentMap.Longitude); + mode = (Mode) bundle.getSerializable(PosoitionMode); if (G.onHelperSetAction != null) { G.onHelperSetAction.onAction(ProtoGlobal.ClientAction.SENDING_LOCATION); } - initComponent(view); + initComponent(view, bundle.getInt("type", 0), bundle.getLong("roomId", 00), bundle.getString("senderId", null)); } else { close(); } @@ -146,7 +281,7 @@ private void close() { popBackStackFragment(); } - private void initComponent(View view) { + private void initComponent(View view, int type, long roomId, String senderId) { SupportMapFragment mapFragment = new SupportMapFragment(); @@ -160,75 +295,114 @@ private void initComponent(View view) { mapFragment.getMapAsync(FragmentMap.this); - Button btnSendPosition = (Button) view.findViewById(R.id.mf_btn_send_position); - btnSendPosition.setBackgroundColor(Color.parseColor(G.appBarColor)); + + rvSendPosition = (RelativeLayout) view.findViewById(R.id.mf_rv_send_position); + + + // rvSendPosition.setBackgroundColor(Color.parseColor(G.appBarColor)); if (mode == Mode.sendPosition) { + fabOpenMap.setVisibility(View.GONE); + rvSendPosition.setVisibility(View.VISIBLE); + rvSeePosition.setVisibility(View.GONE); + rvSendPosition.setOnClickListener(this); - btnSendPosition.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (latitude == null || longitude == null) { + } else if (mode == Mode.seePosition) { + rvSeePosition.setVisibility(View.VISIBLE); + fabOpenMap.setVisibility(View.VISIBLE); + rvSendPosition.setVisibility(View.GONE); + fabOpenMap.setOnClickListener(this); - G.currentActivity.runOnUiThread(new Runnable() { - @Override - public void run() { + Realm realm = Realm.getDefaultInstance(); - HelperError.showSnackMessage(G.fragmentActivity.getResources().getString(R.string.set_position), false); + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fabOpenMap.getLayoutParams(); - } - }); - } else { + if (HelperCalander.isPersianUnicode) { + // params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); + params.anchorGravity = Gravity.LEFT| Gravity.BOTTOM; - try { - mMap.snapshot(new GoogleMap.SnapshotReadyCallback() { - @Override - public void onSnapshotReady(Bitmap bitmap) { + txtUserName.setGravity(Gravity.RIGHT); + ((RelativeLayout.LayoutParams) txtUserName.getLayoutParams()).addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - String path = saveBitmapToFile(bitmap); + } else { + // params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + params.anchorGravity = Gravity.RIGHT| Gravity.BOTTOM; - close(); - if (path.length() > 0) { - //ActivityChat activity = (ActivityChat) mActivity; - //activity.sendPosition(latitude, longitude, path); + txtUserName.setGravity(Gravity.LEFT); + ((RelativeLayout.LayoutParams) txtUserName.getLayoutParams()).addRule(RelativeLayout.ALIGN_PARENT_LEFT); + + } + + if (type == ProtoGlobal.Room.Type.CHAT.getNumber() || type == ProtoGlobal.Room.Type.GROUP.getNumber()) { + + RealmRegisteredInfo realmRegisteredInfo = realm.where(RealmRegisteredInfo.class).equalTo(RealmRegisteredInfoFields.ID, Long.parseLong(senderId)).findFirst(); + txtUserName.setText(realmRegisteredInfo.getDisplayName()); + + setAvatar(Long.parseLong(senderId)); + + + } else { + RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRegisteredInfoFields.ID, roomId).findFirst(); + txtUserName.setText(realmRoom.getTitle()); + + setAvatar(roomId); + + } + + + realm.close(); + // HelperAvatar. - if (G.iSendPositionChat != null) { - G.iSendPositionChat.send(latitude, longitude, path); - } - } - } - }); - } catch (Exception e) { - close(); - //ActivityChat activity = (ActivityChat) mActivity; - //activity.sendPosition(latitude, longitude, null); - - if (G.iSendPositionChat != null) { - G.iSendPositionChat.send(latitude, longitude, null); - } - } - } - } - }); - } else if (mode == Mode.seePosition) { - btnSendPosition.setVisibility(View.GONE); } } + private void setAvatar(long id) { + + HelperAvatar.getAvatar(id, HelperAvatar.AvatarType.ROOM, true, new OnAvatarGet() { + @Override + public void onAvatarGet(final String avatarPath, long ownerId) { + G.handler.post(new Runnable() { + @Override + public void run() { + + // if (!isCloudRoom) { + G.imageLoader.displayImage(AndroidUtils.suitablePath(avatarPath), imgProfile); + // } + } + }); + } + + @Override + public void onShowInitials(final String initials, final String color) { + G.handler.post(new Runnable() { + @Override + public void run() { + // if (!isCloudRoom && imvUserPicture != null) { + imgProfile.setImageBitmap(net.iGap.helper.HelperImageBackColor.drawAlphabetOnPicture((int) G.context.getResources().getDimension(R.dimen.dp60), initials, color)); + // } + } + }); + } + }); + + } + //**************************************************************************************************** /** - * Manipulates the map once available. * This callback is triggered when the map is ready to be used. + * Manipulates the map once available. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ + + @Override public void onMapReady(GoogleMap googleMap) { @@ -240,20 +414,46 @@ public void onMapReady(GoogleMap googleMap) { return; } + if (mode == Mode.seePosition) { + mMap.setMyLocationEnabled(true); + } else { + mMap.setMyLocationEnabled(false); + } - mMap.setMyLocationEnabled(true); LatLng latLng = new LatLng(latitude, longitude); marker = mMap.addMarker(new MarkerOptions().position(latLng).title("position")); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16)); + + LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); + // Define the criteria how to select the locatioin provider -> use + // default + Criteria criteria = new Criteria(); + + String provider; + try { + criteria.setAccuracy(Criteria.ACCURACY_FINE); + provider = locationManager.getBestProvider(criteria, true); + } catch (Exception e) { + provider = locationManager.getBestProvider(criteria, false); + } + + location = locationManager.getLastKnownLocation(provider); + locationManager.requestLocationUpdates(provider, 60, 10, this); + onLocationChanged(location); + + if (mode == Mode.sendPosition) { + mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { - @Override + + @SuppressLint("MissingPermission") public void onMyLocationChange(Location location) { + updatePosition[0] = false; latitude = location.getLatitude(); longitude = location.getLongitude(); @@ -267,11 +467,20 @@ public void onMyLocationChange(Location location) { marker = mMap.addMarker(new MarkerOptions().position(la).title("position")); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(la, 16)); + try { + accuracy.setText("( " + String.format("%.6f", latitude) + " , " + String.format("%.6f", longitude) + " )"); + } catch (Exception e) { + } + + + Log.i("peyman", "log"); mMap.setOnMyLocationChangeListener(null); } }); + mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { + @SuppressLint("MissingPermission") @Override public void onCameraChange(CameraPosition cameraPosition) { @@ -284,11 +493,24 @@ public void onCameraChange(CameraPosition cameraPosition) { latitude = mapCenter.latitude; longitude = mapCenter.longitude; + + mMap.getUiSettings().setCompassEnabled(true); + + + accuracy.setText("( " + String.format("%.6f", latitude) + " , " + String.format("%.6f", longitude) + " )"); + if (marker != null) { marker.remove(); + } marker = mMap.addMarker(new MarkerOptions().position(mapCenter).title("position")); + /* if (marker.getPosition().latitude == fixLat && marker.getPosition().longitude == fixLong) { + mMap.setMyLocationEnabled(false); + } else { + mMap.setMyLocationEnabled(true); + }*/ + } else { updatePosition[0] = true; } @@ -296,9 +518,10 @@ public void onCameraChange(CameraPosition cameraPosition) { }); mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { - @Override + public void onMapClick(LatLng latLng) { + updatePosition[0] = false; latitude = latLng.latitude; longitude = latLng.longitude; @@ -307,11 +530,14 @@ public void onMapClick(LatLng latLng) { marker.remove(); } marker = mMap.addMarker(new MarkerOptions().position(latLng).title("position")); + + mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16)); } }); mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { + @SuppressLint("MissingPermission") @Override public boolean onMyLocationButtonClick() { @@ -332,12 +558,150 @@ public boolean onMyLocationButtonClick() { marker = mMap.addMarker(new MarkerOptions().position(la).title("position")); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(la, 16)); + return false; + + + } + }); + + mMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() { + @SuppressLint("MissingPermission") + @Override + public void onCameraIdle() { + try { + if (mode == Mode.sendPosition) { + + Location loc1 = new Location(""); + loc1.setLatitude(marker.getPosition().latitude); + loc1.setLongitude(marker.getPosition().longitude); + + Location loc2 = new Location(""); + loc2.setLatitude(location.getLatitude()); + loc2.setLongitude(location.getLongitude()); + + if (loc1.distanceTo(loc2) > 35) { + mMap.setMyLocationEnabled(true); + } else { + mMap.setMyLocationEnabled(false); + } + } + } catch (Exception e) { + mMap.setMyLocationEnabled(true); + } + + } + }); + + mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() { + @Override + public void onMapLoaded() { + rvSendPosition.setEnabled(true); } }); } } + @Override + public void onClick(View view) { + if (latitude == null || longitude == null) { + + G.currentActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + + HelperError.showSnackMessage(G.fragmentActivity.getResources().getString(R.string.set_position), false); + + } + }); + } else { + + switch (view.getId()) { + case R.id.mf_rv_send_position: + try { + mMap.snapshot(new GoogleMap.SnapshotReadyCallback() { + @Override + public void onSnapshotReady(Bitmap bitmap) { + + String path = saveMapToFile(bitmap); + + close(); + + if (path.length() > 0) { + //ActivityChat activity = (ActivityChat) mActivity; + //activity.sendPosition(latitude, longitude, path); + + if (G.iSendPositionChat != null) { + G.iSendPositionChat.send(latitude, longitude, path); + } + + } + } + }); + } catch (Exception e) { + close(); + //ActivityChat activity = (ActivityChat) mActivity; + //activity.sendPosition(latitude, longitude, null); + + if (G.iSendPositionChat != null) { + G.iSendPositionChat.send(latitude, longitude, null); + } + } + + break; + + case R.id.mf_fab_openMap: + Uri gmmIntentUri = Uri.parse("geo:" + latitude + "," + longitude + "?q=" + latitude + "," + longitude + "(im here)"); + Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); + mapIntent.setPackage("com.google.android.apps.maps"); + startActivity(mapIntent); + break; + + } + + } + } + + @Override + public void onLocationChanged(Location location) { + + try { + if (mode == Mode.seePosition) { + Location loc1 = new Location(""); + loc1.setLatitude(marker.getPosition().latitude); + loc1.setLongitude(marker.getPosition().longitude); + + Location loc2 = new Location(""); + loc2.setLatitude(location.getLatitude()); + loc2.setLongitude(location.getLongitude()); + + + txtDistance.setText(String.format("%.1f", loc1.distanceTo(loc2)) + " " + getResources().getString(R.string.map_distance) + " "); + + + } + + } catch (Exception e) { + } + + + } + + @Override + public void onStatusChanged(String s, int i, Bundle bundle) { + + } + + @Override + public void onProviderEnabled(String s) { + + } + + @Override + public void onProviderDisabled(String s) { + + } + public enum Mode { sendPosition, seePosition; } diff --git a/app/src/main/java/net/iGap/fragments/FragmentMediaPlayer.java b/app/src/main/java/net/iGap/fragments/FragmentMediaPlayer.java index 2285fa8..a00f220 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentMediaPlayer.java +++ b/app/src/main/java/net/iGap/fragments/FragmentMediaPlayer.java @@ -349,7 +349,7 @@ public void bindView(ViewHolder holder, List payloads) { holder.messageProgress.withDrawable(R.drawable.ic_download, true); holder.iconPlay.setVisibility(View.GONE); - if (HelperDownloadFile.isDownLoading(MusicPlayer.mediaList.get(holder.getAdapterPosition()).getAttachment().getCacheId())) { + if (HelperDownloadFile.getInstance().isDownLoading(MusicPlayer.mediaList.get(holder.getAdapterPosition()).getAttachment().getCacheId())) { startDownload(holder.getAdapterPosition(), holder.messageProgress); } } @@ -505,7 +505,7 @@ private static Realm getRealm() { private void downloadFile(int position, MessageProgress messageProgress) { - if (HelperDownloadFile.isDownLoading(MusicPlayer.mediaList.get(position).getAttachment().getCacheId())) { + if (HelperDownloadFile.getInstance().isDownLoading(MusicPlayer.mediaList.get(position).getAttachment().getCacheId())) { stopDownload(position, messageProgress); } else { startDownload(position, messageProgress); @@ -514,7 +514,7 @@ private void downloadFile(int position, MessageProgress messageProgress) { private void stopDownload(int position, final MessageProgress messageProgress) { - HelperDownloadFile.stopDownLoad(MusicPlayer.mediaList.get(position).getAttachment().getCacheId()); + HelperDownloadFile.getInstance().stopDownLoad(MusicPlayer.mediaList.get(position).getAttachment().getCacheId()); } private void startDownload(final int position, final MessageProgress messageProgress) { @@ -547,7 +547,7 @@ public void run() { }); - HelperDownloadFile.startDownload(MusicPlayer.mediaList.get(position).getMessageId() + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSize(), ProtoFileDownload.FileDownload.Selector.FILE, dirPath, 2, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(MusicPlayer.mediaList.get(position).getMessageId() + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSize(), ProtoFileDownload.FileDownload.Selector.FILE, dirPath, 2, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(String path, final int progress) { diff --git a/app/src/main/java/net/iGap/fragments/FragmentNewGroup.java b/app/src/main/java/net/iGap/fragments/FragmentNewGroup.java index 4ff60b9..5df1c14 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentNewGroup.java +++ b/app/src/main/java/net/iGap/fragments/FragmentNewGroup.java @@ -53,6 +53,7 @@ import net.iGap.module.CircleImageView; import net.iGap.module.FileUploadStructure; import net.iGap.module.LinedEditText; +import net.iGap.module.structs.StructBottomSheet; import net.iGap.proto.ProtoGlobal; import net.iGap.realm.RealmUserInfo; import net.iGap.viewmodel.FragmentNewGroupViewModel; @@ -61,6 +62,7 @@ import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import io.realm.Realm; @@ -104,7 +106,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { FragmentEditImage.completeEditImage = new FragmentEditImage.CompleteEditImage() { @Override - public void result(String path, String message) { + public void result(String path, String message, HashMap textImageList) { pathSaveImage = path; avatarId = System.nanoTime(); @@ -317,9 +319,9 @@ public void deny() { public void onFocusChange(View view, boolean b) { if (b) { - ViewGroupName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + ViewGroupName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { - ViewGroupName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); + ViewGroupName.setBackgroundColor(Color.parseColor(G.lineBorder)); } } }); @@ -445,20 +447,27 @@ private void startChannelRoom(long roomId) { public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); + if (FragmentEditImage.textImageList != null) FragmentEditImage.textImageList.clear(); + if (FragmentEditImage.itemGalleryList != null) FragmentEditImage.itemGalleryList.clear(); + if (requestCode == AttachFile.request_code_TAKE_PICTURE && resultCode == Activity.RESULT_OK) {// result for camera if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ImageHelper.correctRotateImage(AttachFile.mCurrentPhotoPath, true); //rotate image - new HelperFragment(FragmentEditImage.newInstance(AttachFile.mCurrentPhotoPath, false, false)).setReplace(false).load(); + + FragmentEditImage.insertItemList(AttachFile.mCurrentPhotoPath, false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); } else { ImageHelper.correctRotateImage(AttachFile.imagePath, true); //rotate image - new HelperFragment(FragmentEditImage.newInstance(AttachFile.imagePath, false, false)).setReplace(false).load(); + FragmentEditImage.insertItemList(AttachFile.imagePath, false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); } } else if (requestCode == request_code_image_from_gallery_single_select && resultCode == Activity.RESULT_OK) {// result for gallery if (data != null) { - new HelperFragment(FragmentEditImage.newInstance(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false, false)).setReplace(false).load(); + FragmentEditImage.insertItemList(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); } } } diff --git a/app/src/main/java/net/iGap/fragments/FragmentPayment.java b/app/src/main/java/net/iGap/fragments/FragmentPayment.java new file mode 100644 index 0000000..542c362 --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentPayment.java @@ -0,0 +1,62 @@ +package net.iGap.fragments; + + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.iGap.R; +import net.iGap.databinding.FragmentPaymentBinding; +import net.iGap.interfaces.IBackHandler; +import net.iGap.viewmodel.FragmentPaymentViewModel; + +/** + * A simple {@link Fragment} subclass. + */ +public class FragmentPayment extends BaseFragment { + + private FragmentPaymentViewModel fragmentPaymentViewModel; + private FragmentPaymentBinding fragmentPaymentBinding; + + + public static FragmentPayment newInstance() { + return new FragmentPayment(); + } + + public FragmentPayment() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentPaymentBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_payment, container, false); + return attachToSwipeBack(fragmentPaymentBinding.getRoot()); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initDataBinding(getArguments()); + } + + private void initDataBinding(Bundle arguments) { + + fragmentPaymentViewModel = new FragmentPaymentViewModel(arguments); + fragmentPaymentBinding.setFragmentPaymentViewModel(fragmentPaymentViewModel); + + IBackHandler iBackHandler = new IBackHandler() { + @Override + public void onBack() { + popBackStackFragment(); + } + }; + + fragmentPaymentBinding.setBackHandler(iBackHandler); + + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/fragments/FragmentPaymentBill.java b/app/src/main/java/net/iGap/fragments/FragmentPaymentBill.java new file mode 100644 index 0000000..f10b831 --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentPaymentBill.java @@ -0,0 +1,121 @@ +package net.iGap.fragments; + + +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.google.zxing.integration.android.IntentIntegrator; +import com.google.zxing.integration.android.IntentResult; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.databinding.FragmentPaymentBillBinding; +import net.iGap.interfaces.IBackHandler; +import net.iGap.viewmodel.FragmentPaymentBillViewModel; + +import static net.iGap.activities.ActivityMain.requestCodeBarcode; +import static net.iGap.viewmodel.FragmentPaymentBillViewModel.getCompany; + + +public class FragmentPaymentBill extends BaseFragment { + + private FragmentPaymentBillBinding fragmentPaymentBillBinding; + + public static FragmentPaymentBill newInstance(int resTitleId) { + Bundle args = new Bundle(); + args.putInt("title", resTitleId); + FragmentPaymentBill fragmentPaymentBill = new FragmentPaymentBill(); + fragmentPaymentBill.setArguments(args); + return fragmentPaymentBill; + } + + public FragmentPaymentBill() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentPaymentBillBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_payment_bill, container, false); + return attachToSwipeBack(fragmentPaymentBillBinding.getRoot()); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + int resTitleId = getArguments().getInt("title"); + + FragmentPaymentBillViewModel fragmentPaymentBillViewModel = new FragmentPaymentBillViewModel(FragmentPaymentBill.this, fragmentPaymentBillBinding, resTitleId); + fragmentPaymentBillBinding.setFragmentPaymentBillViewModel(fragmentPaymentBillViewModel); + + IBackHandler iBackHandler = new IBackHandler() { + @Override + public void onBack() { + popBackStackFragment(); + } + }; + + fragmentPaymentBillBinding.setBackHandler(iBackHandler); + } + + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == requestCodeBarcode) { + IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data); + if (result.getContents() != null) { + String barCode = result.getContents(); + if (barCode.length() == 26) { + String billId = barCode.substring(0, 13); + String payId = barCode.substring(13, 26); + String company_type = barCode.substring(11, 12); + String price = barCode.substring(13, 21); + + while (payId.startsWith("0")) { + payId = payId.substring(1); + } + + fragmentPaymentBillBinding.fpbEdtBillId.setText(billId); + fragmentPaymentBillBinding.fpbEdtPayId.setText(payId); + fragmentPaymentBillBinding.fpbEdtPrice.setText(addCommasToNumericString((Integer.parseInt(price) * 1000) + "")); + fragmentPaymentBillBinding.fpbImvCompany.setImageResource(getCompany(company_type)); + + fragmentPaymentBillBinding.getFragmentPaymentBillViewModel().observeAmount.set(true); + + } + } + } + + + } + + public static String addCommasToNumericString(String digits) { + String result = ""; + int len = digits.length(); + int nDigits = 0; + + for (int i = len - 1; i >= 0; i--) { + result = digits.charAt(i) + result; + nDigits++; + if (((nDigits % 3) == 0) && (i > 0)) { + result = "," + result; + } + } + return (result); + } + + @Override + public void onDestroy() { + super.onDestroy(); + G.onMplResult = null; + } + +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/fragments/FragmentPaymentCharge.java b/app/src/main/java/net/iGap/fragments/FragmentPaymentCharge.java new file mode 100644 index 0000000..08c2621 --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentPaymentCharge.java @@ -0,0 +1,68 @@ +package net.iGap.fragments; + + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.databinding.FragmentPaymentChargeBinding; +import net.iGap.interfaces.IBackHandler; +import net.iGap.viewmodel.FragmentPaymentChargeViewModel; + +/** + * A simple {@link Fragment} subclass. + */ +public class FragmentPaymentCharge extends BaseFragment { + + private FragmentPaymentChargeViewModel fragmentPaymentChargeViewModel; + private FragmentPaymentChargeBinding fragmentPaymentChargeBinding; + + public static FragmentPaymentCharge newInstance() { + return new FragmentPaymentCharge(); + } + + public FragmentPaymentCharge() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentPaymentChargeBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_payment_charge, container, false); + return attachToSwipeBack(fragmentPaymentChargeBinding.getRoot()); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initDataBinding(getArguments()); + } + + private void initDataBinding(Bundle arguments) { + + fragmentPaymentChargeViewModel = new FragmentPaymentChargeViewModel(fragmentPaymentChargeBinding); + fragmentPaymentChargeBinding.setFragmentPaymentChargeViewModel(fragmentPaymentChargeViewModel); + + IBackHandler iBackHandler = new IBackHandler() { + @Override + public void onBack() { + popBackStackFragment(); + } + }; + + fragmentPaymentChargeBinding.setBackHandler(iBackHandler); + + } + + @Override + public void onDestroy() { + super.onDestroy(); + G.onMplResult = null; + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/fragments/FragmentPaymentInquiry.java b/app/src/main/java/net/iGap/fragments/FragmentPaymentInquiry.java new file mode 100644 index 0000000..c46721b --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentPaymentInquiry.java @@ -0,0 +1,76 @@ +package net.iGap.fragments; + + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.iGap.R; +import net.iGap.databinding.FragmentPaymentInquiryBinding; +import net.iGap.interfaces.IBackHandler; +import net.iGap.viewmodel.FragmentPaymentInquiryViewModel; + +/** + * A simple {@link Fragment} subclass. + */ +public class FragmentPaymentInquiry extends BaseFragment { + + private FragmentPaymentInquiryBinding fragmentPaymentInquiryBinding; + + + public static FragmentPaymentInquiry newInstance(FragmentPaymentInquiryViewModel.OperatorType type, String phone) { + + Bundle args = new Bundle(); + args.putSerializable("type", type); + + if (phone != null && phone.length() > 0) { + args.putString("phone", phone); + } + + FragmentPaymentInquiry fragmentPaymentInquiry = new FragmentPaymentInquiry(); + fragmentPaymentInquiry.setArguments(args); + + return fragmentPaymentInquiry; + } + + public FragmentPaymentInquiry() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentPaymentInquiryBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_payment_inquiry, container, false); + return attachToSwipeBack(fragmentPaymentInquiryBinding.getRoot()); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + FragmentPaymentInquiryViewModel.OperatorType type = (FragmentPaymentInquiryViewModel.OperatorType) getArguments().getSerializable("type"); + + FragmentPaymentInquiryViewModel fragmentPaymentInquiryViewModel = new FragmentPaymentInquiryViewModel(fragmentPaymentInquiryBinding, type); + fragmentPaymentInquiryBinding.setFragmentPaymentInquiryViewModel(fragmentPaymentInquiryViewModel); + + IBackHandler iBackHandler = new IBackHandler() { + @Override + public void onBack() { + popBackStackFragment(); + } + }; + fragmentPaymentInquiryBinding.setBackHandler(iBackHandler); + + String phone = getArguments().getString("phone"); + if (phone != null && phone.length() > 0) { + fragmentPaymentInquiryBinding.fpiEdtMci.setText(phone); + fragmentPaymentInquiryViewModel.onInquiryClick(null); + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/fragments/FragmentQrCodeNewDevice.java b/app/src/main/java/net/iGap/fragments/FragmentQrCodeNewDevice.java deleted file mode 100644 index 3a407e1..0000000 --- a/app/src/main/java/net/iGap/fragments/FragmentQrCodeNewDevice.java +++ /dev/null @@ -1,112 +0,0 @@ -/* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ - -package net.iGap.fragments; - -import android.graphics.PointF; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.RelativeLayout; - -import com.dlazaro66.qrcodereaderview.QRCodeReaderView; - -import net.iGap.G; -import net.iGap.R; -import net.iGap.activities.ActivityMain; -import net.iGap.module.PointsOverlayView; -import net.iGap.request.RequestUserVerifyNewDevice; - -import static net.iGap.R.id.apvq_qrdecoderview; - -public class FragmentQrCodeNewDevice extends BaseFragment implements QRCodeReaderView.OnQRCodeReadListener { - - private QRCodeReaderView myDecoderView; - private PointsOverlayView pointsOverlayView; - private boolean isFirst = true; - - public static FragmentQrCodeNewDevice newInstance() { - return new FragmentQrCodeNewDevice(); - } - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.activity_qr_code_new_device, container, false); - } - - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - myDecoderView = (QRCodeReaderView) view.findViewById(apvq_qrdecoderview); - myDecoderView.setOnQRCodeReadListener(this); - - // Use this function to enable/disable decoding - myDecoderView.setQRDecodingEnabled(true); - - // Use this function to change the autofocus interval (default is 5 secs) - myDecoderView.setAutofocusInterval(2000L); - - // Use this function to enable/disable Torch - //myDecoderView.setTorchEnabled(true); - - // Use this function to set front camera preview - //myDecoderView.setFrontCamera(); - - // Use this function to set back camera preview - myDecoderView.setBackCamera(); - - pointsOverlayView = (PointsOverlayView) view.findViewById(R.id.points_overlay_view); - - myDecoderView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - } - }); - - RelativeLayout root = (RelativeLayout) view.findViewById(R.id.root_qrCoderView); - - root.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - popBackStackFragment(); - - if (G.fragmentActivity != null) { - ((ActivityMain) G.fragmentActivity).openNavigation(); - } - - G.fragmentActivity.overridePendingTransition(0, 0); - } - }); - } - - @Override - public void onPause() { - super.onPause(); - G.fragmentActivity.overridePendingTransition(0, 0); - } - - @Override - public void onQRCodeRead(String text, PointF[] points) { - if (isFirst) { - isFirst = false; - new RequestUserVerifyNewDevice().verifyNewDevice(text); - } - pointsOverlayView.setPoints(points); - popBackStackFragment(); - - if (G.fragmentActivity != null) { - ((ActivityMain) G.fragmentActivity).openNavigation(); - } - } -} diff --git a/app/src/main/java/net/iGap/fragments/FragmentRegister.java b/app/src/main/java/net/iGap/fragments/FragmentRegister.java index 51f212d..67e1b2e 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentRegister.java +++ b/app/src/main/java/net/iGap/fragments/FragmentRegister.java @@ -135,22 +135,21 @@ public void deny() { txtTitleToolbar.setTypeface(titleTypeface); - if (G.selectedLanguage.equals("fa") || G.selectedLanguage.equals("ar")) { - - TextView rg_txt_verify_connect = fragmentRegisterBinding.rgTxtVerifyConnect; - rg_txt_verify_connect.setTypeface(titleTypeface); - - - TextView rg_txt_verify_sms = fragmentRegisterBinding.rgTxtVerifySms; - rg_txt_verify_sms.setTypeface(titleTypeface); - - TextView rg_txt_verify_generate = fragmentRegisterBinding.rgTxtVerifyKey; - rg_txt_verify_generate.setTypeface(titleTypeface); - - TextView rg_txt_verify_register = fragmentRegisterBinding.rgTxtVerifyServer; - rg_txt_verify_register.setTypeface(titleTypeface); - - } +// if (G.selectedLanguage.equals("fa") || G.selectedLanguage.equals("ar")) { +// +// TextView rg_txt_verify_connect = fragmentRegisterBinding.rgTxtVerifyConnect; +// rg_txt_verify_connect.setTypeface(G.typeface_IRANSansMobile); +// +// TextView rg_txt_verify_sms = fragmentRegisterBinding.rgTxtVerifySms; +// rg_txt_verify_sms.setTypeface(G.typeface_IRANSansMobile); +// +// TextView rg_txt_verify_generate = fragmentRegisterBinding.rgTxtVerifyKey; +// rg_txt_verify_generate.setTypeface(G.typeface_IRANSansMobile); +// +// TextView rg_txt_verify_register = fragmentRegisterBinding.rgTxtVerifyServer; +// rg_txt_verify_register.setTypeface(G.typeface_IRANSansMobile); +// +// } ProgressBar rg_prg_verify_connect = fragmentRegisterBinding.rgPrgVerifyConnect; diff --git a/app/src/main/java/net/iGap/fragments/FragmentRegistrationNickname.java b/app/src/main/java/net/iGap/fragments/FragmentRegistrationNickname.java index 8dd3be6..ea9cf32 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentRegistrationNickname.java +++ b/app/src/main/java/net/iGap/fragments/FragmentRegistrationNickname.java @@ -48,11 +48,13 @@ import net.iGap.module.AttachFile; import net.iGap.module.EditTextAdjustPan; import net.iGap.module.FileUploadStructure; +import net.iGap.module.structs.StructBottomSheet; import net.iGap.proto.ProtoGlobal; import net.iGap.request.RequestUserAvatarAdd; import net.iGap.viewmodel.FragmentRegistrationNicknameViewModel; import java.io.IOException; +import java.util.HashMap; import static android.app.Activity.RESULT_OK; @@ -134,7 +136,7 @@ public void afterTextChanged(Editable editable) { FragmentEditImage.completeEditImage = new FragmentEditImage.CompleteEditImage() { @Override - public void result(String path, String message) { + public void result(String path, String message, HashMap textImageList) { pathImageUser = path; @@ -178,6 +180,11 @@ public void onResume() { public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { + + if (FragmentEditImage.textImageList != null) FragmentEditImage.textImageList.clear(); + if (FragmentEditImage.itemGalleryList != null) + FragmentEditImage.itemGalleryList.clear(); + switch (requestCode) { case AttachFile.request_code_TAKE_PICTURE: String path = ""; @@ -187,8 +194,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { path = AttachFile.imagePath; } ImageHelper.correctRotateImage(path, true); //rotate image - G.fragmentActivity.getSupportFragmentManager().beginTransaction(). - add(R.id.ar_layout_root, FragmentEditImage.newInstance(path, false, true)) + + FragmentEditImage.insertItemList(path, false); + G.fragmentActivity.getSupportFragmentManager().beginTransaction().add(R.id.ar_layout_root, FragmentEditImage.newInstance(path, false, true, 0)) .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_exit_in_right, R.anim.slide_exit_out_left).commitAllowingStateLoss(); break; @@ -197,8 +205,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (data.getData() == null) { return; } + + FragmentEditImage.insertItemList(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false); G.fragmentActivity.getSupportFragmentManager().beginTransaction(). - add(R.id.ar_layout_root, FragmentEditImage.newInstance(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false, true)) + add(R.id.ar_layout_root, FragmentEditImage.newInstance(null, false, true, 0)) .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_exit_in_right, R.anim.slide_exit_out_left).commitAllowingStateLoss(); } break; diff --git a/app/src/main/java/net/iGap/fragments/FragmentSetting.java b/app/src/main/java/net/iGap/fragments/FragmentSetting.java index 6756e18..be64fc6 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentSetting.java +++ b/app/src/main/java/net/iGap/fragments/FragmentSetting.java @@ -3,10 +3,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.content.res.ColorStateList; import android.content.res.Configuration; import android.databinding.DataBindingUtil; import android.graphics.Color; -import android.graphics.drawable.GradientDrawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -18,6 +18,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.CompoundButton; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -46,6 +47,7 @@ import net.iGap.module.EmojiTextViewE; import net.iGap.module.FileUploadStructure; import net.iGap.module.SUID; +import net.iGap.module.structs.StructBottomSheet; import net.iGap.proto.ProtoGlobal; import net.iGap.request.RequestUserAvatarAdd; import net.iGap.request.RequestUserProfileGetBio; @@ -55,6 +57,7 @@ import java.io.File; import java.io.IOException; +import java.util.HashMap; import io.realm.Realm; @@ -142,37 +145,9 @@ public void back() { } }; - //*********************** - GradientDrawable bgShape = (GradientDrawable) fragmentSettingBinding.asnImgTitleBarColor.getBackground(); - bgShape.setColor(Color.parseColor(G.appBarColor)); - - //*********************** - - GradientDrawable bgShapeNotification = (GradientDrawable) fragmentSettingBinding.asnImgNotificationColor.getBackground(); - bgShapeNotification.setColor(Color.parseColor(G.notificationColor)); - - //*********************** - - GradientDrawable bgShapeToggleBottomColor = (GradientDrawable) fragmentSettingBinding.asnImgToggleBottonColor.getBackground(); - bgShapeToggleBottomColor.setColor(Color.parseColor(G.toggleButtonColor)); - - /* - page for show all image user - */ - GradientDrawable bgShapeSendAndAttachColor = (GradientDrawable) fragmentSettingBinding.asnImgSendAndAttachColor.getBackground(); - bgShapeSendAndAttachColor.setColor(Color.parseColor(G.attachmentColor)); - - - //*********************** - - GradientDrawable bgShapeHeaderTextColor = (GradientDrawable) fragmentSettingBinding.asnImgDefaultHeaderFontColor.getBackground(); - bgShapeHeaderTextColor.setColor(Color.parseColor(G.headerTextColor)); - - //*********************** - - GradientDrawable bgShapeProgressColor = (GradientDrawable) fragmentSettingBinding.asnImgDefaultProgressColor.getBackground(); - bgShapeProgressColor.setColor(Color.parseColor(G.progressColor)); + fragmentSettingBinding.stFabSetPic.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom))); + fragmentSettingBinding.stFabSetPic.setColorFilter(Color.WHITE); fragmentSettingBinding.stFabSetPic.setOnClickListener(new View.OnClickListener() { @Override @@ -216,7 +191,7 @@ public void run() { FragmentEditImage.completeEditImage = new FragmentEditImage.CompleteEditImage() { @Override - public void result(String path, String message) { + public void result(String path, String message, HashMap textImageList) { pathSaveImage = path; long lastUploadedAvatarId = idAvatar + 1L; @@ -308,20 +283,32 @@ public void onPause() { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); + + if (FragmentEditImage.textImageList != null) FragmentEditImage.textImageList.clear(); + if (FragmentEditImage.itemGalleryList != null) FragmentEditImage.itemGalleryList.clear(); + + if (requestCode == AttachFile.request_code_TAKE_PICTURE && resultCode == RESULT_OK) {// result for camera + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ImageHelper.correctRotateImage(AttachFile.mCurrentPhotoPath, true); //rotate image - new HelperFragment(FragmentEditImage.newInstance(AttachFile.mCurrentPhotoPath, false, false)).setReplace(false).load(); + + FragmentEditImage.insertItemList(AttachFile.mCurrentPhotoPath, false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); } else { ImageHelper.correctRotateImage(pathSaveImage, true); //rotate image - new HelperFragment(FragmentEditImage.newInstance(pathSaveImage, false, false)).setReplace(false).load(); + + FragmentEditImage.insertItemList(pathSaveImage, false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); } } else if (requestCode == request_code_image_from_gallery_single_select && resultCode == RESULT_OK) {// result for gallery if (data != null) { if (data.getData() == null) { return; } - new HelperFragment(FragmentEditImage.newInstance(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false, false)).setReplace(false).load(); + FragmentEditImage.insertItemList(AttachFile.getFilePathFromUriAndCheckForAndroid7(data.getData(), HelperGetDataFromOtherApp.FileType.image), false); + new HelperFragment(FragmentEditImage.newInstance(null, false, false, 0)).setReplace(false).load(); } } } diff --git a/app/src/main/java/net/iGap/fragments/FragmentShearedMedia.java b/app/src/main/java/net/iGap/fragments/FragmentShearedMedia.java index eac15d1..404a130 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentShearedMedia.java +++ b/app/src/main/java/net/iGap/fragments/FragmentShearedMedia.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.fragments; @@ -106,6 +106,7 @@ public class FragmentShearedMedia extends BaseFragment { private static final String ROOM_ID = "RoomId"; + private static final String USERNAME = "USERNAME"; public static ArrayList list = new ArrayList<>(); private static long countOFImage = 0; private static long countOFVIDEO = 0; @@ -145,6 +146,9 @@ public class FragmentShearedMedia extends BaseFragment { private boolean isThereAnyMoreItemToLoad = false; private long nextMessageId = 0; private long roomId = 0; + private MaterialDesignTextView btnGoToPage; + public static GoToPositionFromShardMedia goToPositionFromShardMedia; + public static boolean goToPosition = false; public static FragmentShearedMedia newInstance(long roomId) { Bundle args = new Bundle(); @@ -346,6 +350,20 @@ public void onClick(View view) { } }); + btnGoToPage = (MaterialDesignTextView) view.findViewById(R.id.asm_btn_goToPage); + btnGoToPage.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + long messageId = SelectedList.get(0); + RealmRoomMessage.setGap(messageId); + goToPositionFromShardMedia.goToPosition(messageId); + goToPosition = true; + popBackStackFragment(); + adapter.resetSelected(); + popBackStackFragment(); + } + }); + MaterialDesignTextView btnForwardSelected = (MaterialDesignTextView) view.findViewById(R.id.asm_btn_forward_selected); btnForwardSelected.setOnClickListener(new View.OnClickListener() { @Override @@ -462,6 +480,11 @@ private void callBack(boolean result, int whatAction, String number) { if (result) { ll_AppBarSelected.setVisibility(View.VISIBLE); txtNumberOfSelected.setText(number); + if (SelectedList.size() == 1) { + btnGoToPage.setVisibility(View.VISIBLE); + } else { + btnGoToPage.setVisibility(View.GONE); + } } else { ll_AppBarSelected.setVisibility(View.GONE); } @@ -1106,7 +1129,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { holder1.messageProgress.setTag(mList.get(position).messageId); holder1.messageProgress.withDrawable(R.drawable.ic_download, true); - if (HelperDownloadFile.isDownLoading(mList.get(position).item.getAttachment().getCacheId())) { + if (HelperDownloadFile.getInstance().isDownLoading(mList.get(position).item.getAttachment().getCacheId())) { startDownload(position, holder1.messageProgress); } } @@ -1217,7 +1240,7 @@ public void run() { } }); - HelperDownloadFile.startDownload(mList.get(position).messageId + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSize(), ProtoFileDownload.FileDownload.Selector.FILE, dirPath, 2, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(mList.get(position).messageId + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSize(), ProtoFileDownload.FileDownload.Selector.FILE, dirPath, 2, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(String path, final int progress) { @@ -1282,12 +1305,12 @@ public void run() { private void stopDownload(int position) { - HelperDownloadFile.stopDownLoad(mList.get(position).item.getAttachment().getCacheId()); + HelperDownloadFile.getInstance().stopDownLoad(mList.get(position).item.getAttachment().getCacheId()); } private void downloadFile(int position, MessageProgress messageProgress) { - if (HelperDownloadFile.isDownLoading(mList.get(position).item.getAttachment().getCacheId())) { + if (HelperDownloadFile.getInstance().isDownLoading(mList.get(position).item.getAttachment().getCacheId())) { stopDownload(position); } else { startDownload(position, messageProgress); @@ -1457,7 +1480,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) if (at.getSmallThumbnail() != null) { if (at.getSmallThumbnail().getSize() > 0) { - HelperDownloadFile.startDownload(mList.get(position).messageId + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSmallThumbnail().getSize(), ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL, "", 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(mList.get(position).messageId + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSmallThumbnail().getSize(), ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL, "", 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, int progress) { @@ -1593,7 +1616,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) if (at.getSmallThumbnail() != null) { if (at.getSmallThumbnail().getSize() > 0) { - HelperDownloadFile.startDownload(mList.get(position).messageId + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSmallThumbnail().getSize(), ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL, "", 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(mList.get(position).messageId + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSmallThumbnail().getSize(), ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL, "", 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, int progress) { @@ -1672,7 +1695,7 @@ void openSelectedItem(int position, RecyclerView.ViewHolder holder) { private void playVideo(int position, View itemView) { SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - if (sharedPreferences.getInt(SHP_SETTING.KEY_DEFAULT_PLAYER, 0) == 1) { + if (sharedPreferences.getInt(SHP_SETTING.KEY_DEFAULT_PLAYER, 1) == 0) { openVideoByDefaultApp(position); } else { long selectedFileToken = mNewList.get(position).messageId; @@ -1909,7 +1932,7 @@ public void onClick(View view) { if (at.getSmallThumbnail() != null) { if (at.getSmallThumbnail().getSize() > 0) { - HelperDownloadFile.startDownload(mList.get(position).messageId + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSmallThumbnail().getSize(), ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL, "", 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(mList.get(position).messageId + "", at.getToken(), at.getUrl(), at.getCacheId(), at.getName(), at.getSmallThumbnail().getSize(), ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL, "", 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, int progress) { @@ -2147,4 +2170,8 @@ public ViewHolder(View view) { } } } + + public interface GoToPositionFromShardMedia { + void goToPosition(Long aLong); + } } diff --git a/app/src/main/java/net/iGap/fragments/FragmentShowAvatars.java b/app/src/main/java/net/iGap/fragments/FragmentShowAvatars.java index 46514df..17f764f 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentShowAvatars.java +++ b/app/src/main/java/net/iGap/fragments/FragmentShowAvatars.java @@ -603,7 +603,7 @@ public Object instantiateItem(View container, final int position) { final RealmAttachment ra = avatarList.get(position).getFile(); - if (HelperDownloadFile.isDownLoading(ra.getCacheId())) { + if (HelperDownloadFile.getInstance().isDownLoading(ra.getCacheId())) { progress.withDrawable(R.drawable.ic_cancel, true); startDownload(position, progress, touchImageView); } else { @@ -638,7 +638,7 @@ public Object instantiateItem(View container, final int position) { final String filePathTumpnail = AndroidUtils.getFilePathWithCashId(ra.getCacheId(), ra.getName(), G.DIR_TEMP, true); if (selector != null && fileSize > 0) { - HelperDownloadFile.startDownload(System.currentTimeMillis() + "", ra.getToken(), ra.getUrl(), ra.getCacheId(), ra.getName(), fileSize, selector, "", 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(System.currentTimeMillis() + "", ra.getToken(), ra.getUrl(), ra.getCacheId(), ra.getName(), fileSize, selector, "", 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, int progress) { @@ -672,8 +672,8 @@ public void onClick(View view) { String _cashId = avatarList.get(position).getFile().getCacheId(); - if (HelperDownloadFile.isDownLoading(_cashId)) { - HelperDownloadFile.stopDownLoad(_cashId); + if (HelperDownloadFile.getInstance().isDownLoading(_cashId)) { + HelperDownloadFile.getInstance().stopDownLoad(_cashId); } else { progress.withDrawable(R.drawable.ic_cancel, true); startDownload(position, progress, touchImageView); @@ -722,7 +722,7 @@ public void run() { }); - HelperDownloadFile.startDownload(System.currentTimeMillis() + "", ra.getToken(), ra.getUrl(), ra.getCacheId(), ra.getName(), ra.getSize(), ProtoFileDownload.FileDownload.Selector.FILE, dirPath, 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(System.currentTimeMillis() + "", ra.getToken(), ra.getUrl(), ra.getCacheId(), ra.getName(), ra.getSize(), ProtoFileDownload.FileDownload.Selector.FILE, dirPath, 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, final int progres) { G.currentActivity.runOnUiThread(new Runnable() { diff --git a/app/src/main/java/net/iGap/fragments/FragmentShowImage.java b/app/src/main/java/net/iGap/fragments/FragmentShowImage.java index a32de1f..5fa5b23 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentShowImage.java +++ b/app/src/main/java/net/iGap/fragments/FragmentShowImage.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.fragments; @@ -101,12 +101,14 @@ public class FragmentShowImage extends BaseFragment { private String path; private String type = null; private boolean isLockScreen = false; + private boolean isFocusable = false; private Realm realmShowImage; private ViewGroup rooShowImage; private ViewGroup mainShowImage; private ExitFragmentTransition exitFragmentTransition; private TouchImageView touchImageViewTmp = null; private int lastOrientation = 0; + public static FocusAudioListener focusAudioListener; ArrayList mTextureViewTmp = new ArrayList<>(); public static FragmentShowImage newInstance() { @@ -309,6 +311,31 @@ public void onComplete(RippleView rippleView) { toolbarShowImage = (LinearLayout) view.findViewById(R.id.toolbarShowImage); initViewPager(); + + + focusAudioListener = new FocusAudioListener() { + @Override + public void audioPlay(boolean isPlay) { + + if (isPlay) { + if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { + mMediaPlayer.pause(); + isLockScreen = true; + isFocusable = true; + } + } else { + if (mMediaPlayer != null && isFocusable) { + int length = mMediaPlayer.getCurrentPosition(); + mMediaPlayer.seekTo(length); + mMediaPlayer.start(); + isLockScreen = true; + isFocusable = false; + + } + } + + } + }; } //*************************************************************************************** @@ -554,6 +581,8 @@ public void onDetach() { videoController.hide(); videoController = null; } + + focusAudioListener = null; } @Override @@ -563,6 +592,9 @@ public void onPause() { mMediaPlayer.pause(); isLockScreen = true; } + if (videoController != null && videoController.isShowing()) { + videoController.hide(); + } } @Override @@ -570,7 +602,6 @@ public void onResume() { super.onResume(); if (isLockScreen) { - if (videoController != null) { videoController.show(); } @@ -618,7 +649,7 @@ public void onClick(View v) { final RealmRoomMessage rm = RealmRoomMessage.getFinalMessage(mFList.get(position)); if (rm != null && rm.isValid()) { - if (HelperDownloadFile.isDownLoading(rm.getAttachment().getCacheId())) { + if (HelperDownloadFile.getInstance().isDownLoading(rm.getAttachment().getCacheId())) { progress.withDrawable(R.drawable.ic_cancel, true); startDownload(position, progress, touchImageView, imgPlay, mTextureView); } else { @@ -678,7 +709,7 @@ public void run() { final String filePathTumpnail = AndroidUtils.getFilePathWithCashId(rm.getAttachment().getCacheId(), rm.getAttachment().getName(), G.DIR_TEMP, true); if (selector != null && fileSize > 0) { - HelperDownloadFile.startDownload(System.currentTimeMillis() + "", rm.getAttachment().getToken(), rm.getAttachment().getUrl(), rm.getAttachment().getCacheId(), rm.getAttachment().getName(), fileSize, selector, "", 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(System.currentTimeMillis() + "", rm.getAttachment().getToken(), rm.getAttachment().getUrl(), rm.getAttachment().getCacheId(), rm.getAttachment().getName(), fileSize, selector, "", 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, int progress) { @@ -709,8 +740,8 @@ public void onClick(View view) { String _cashID = mFList.get(position).getForwardMessage() != null ? mFList.get(position).getForwardMessage().getAttachment().getCacheId() : mFList.get(position).getAttachment().getCacheId(); - if (HelperDownloadFile.isDownLoading(_cashID)) { - HelperDownloadFile.stopDownLoad(_cashID); + if (HelperDownloadFile.getInstance().isDownLoading(_cashID)) { + HelperDownloadFile.getInstance().stopDownLoad(_cashID); } else { progress.withDrawable(R.drawable.ic_cancel, true); startDownload(position, progress, touchImageView, imgPlay, mTextureView); @@ -846,7 +877,7 @@ public void run() { }); - HelperDownloadFile.startDownload(System.currentTimeMillis() + "", rm.getAttachment().getToken(), rm.getAttachment().getUrl(), rm.getAttachment().getCacheId(), rm.getAttachment().getName(), rm.getAttachment().getSize(), ProtoFileDownload.FileDownload.Selector.FILE, dirPath, 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(System.currentTimeMillis() + "", rm.getAttachment().getToken(), rm.getAttachment().getUrl(), rm.getAttachment().getCacheId(), rm.getAttachment().getName(), rm.getAttachment().getSize(), ProtoFileDownload.FileDownload.Selector.FILE, dirPath, 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, final int progres) { G.currentActivity.runOnUiThread(new Runnable() { @@ -1086,4 +1117,10 @@ private void getRealSize(MediaPlayer mp, TextureView mTextureView) { mTextureView.setLayoutParams(lp); } + public interface FocusAudioListener { + + void audioPlay(boolean isPlay); + + } + } \ No newline at end of file diff --git a/app/src/main/java/net/iGap/fragments/FragmentThemColor.java b/app/src/main/java/net/iGap/fragments/FragmentThemColor.java new file mode 100644 index 0000000..d3d1c7a --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentThemColor.java @@ -0,0 +1,58 @@ +package net.iGap.fragments; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.iGap.R; +import net.iGap.databinding.FragmentThemColorBinding; +import net.iGap.viewmodel.FragmentThemColorViewModel; + + +/** + * A simple {@link Fragment} subclass. + */ +public class FragmentThemColor extends BaseFragment { + + + private FragmentThemColorViewModel fragmentThemColorViewModel; + private FragmentThemColorBinding fragmentThemColorBinding; + + + public FragmentThemColor() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Inflate the layout for this fragment + fragmentThemColorBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_them_color, container, false); + return attachToSwipeBack(fragmentThemColorBinding.getRoot()); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + initDataBinding(); + fragmentThemColorBinding.stnsRippleBack.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // mActivity.getSupportFragmentManager().popBackStack(); + popBackStackFragment(); + } + }); + } + + private void initDataBinding() { + fragmentThemColorViewModel = new FragmentThemColorViewModel(this, fragmentThemColorBinding); + fragmentThemColorBinding.setFragmentThemColorViewModel(fragmentThemColorViewModel); + + } +} diff --git a/app/src/main/java/net/iGap/fragments/FragmentThemColorCustom.java b/app/src/main/java/net/iGap/fragments/FragmentThemColorCustom.java new file mode 100644 index 0000000..51872a9 --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentThemColorCustom.java @@ -0,0 +1,58 @@ +package net.iGap.fragments; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.iGap.R; +import net.iGap.databinding.FragmentThemColorCustomBinding; +import net.iGap.viewmodel.FragmentThemColorCustomViewModel; + + +/** + * A simple {@link Fragment} subclass. + */ +public class FragmentThemColorCustom extends BaseFragment { + + + private FragmentThemColorCustomViewModel fragmentThemColorCustomViewModel; + private FragmentThemColorCustomBinding fragmentThemColorCustomBinding; + + + public FragmentThemColorCustom() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Inflate the layout for this fragment + fragmentThemColorCustomBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_them_color_custom, container, false); + return attachToSwipeBack(fragmentThemColorCustomBinding.getRoot()); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + initDataBinding(); + fragmentThemColorCustomBinding.stnsRippleBack.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // mActivity.getSupportFragmentManager().popBackStack(); + popBackStackFragment(); + } + }); + } + + private void initDataBinding() { + fragmentThemColorCustomViewModel = new FragmentThemColorCustomViewModel(this, fragmentThemColorCustomBinding); + fragmentThemColorCustomBinding.setFragmentThemColorCustomViewModel(fragmentThemColorCustomViewModel); + + } +} diff --git a/app/src/main/java/net/iGap/fragments/FragmentWallet.java b/app/src/main/java/net/iGap/fragments/FragmentWallet.java new file mode 100644 index 0000000..67ad769 --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentWallet.java @@ -0,0 +1,58 @@ +package net.iGap.fragments; + + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.iGap.R; +import net.iGap.databinding.FragmentWalletBinding; +import net.iGap.interfaces.IBackHandler; +import net.iGap.viewmodel.FragmentWalletViewModel; + +/** + * A simple {@link Fragment} subclass. + */ +public class FragmentWallet extends BaseFragment { + + private FragmentWalletBinding fragmentWalletBinding; + + public static FragmentWallet newInstance() { + return new FragmentWallet(); + } + + public FragmentWallet() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentWalletBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_wallet, container, false); + return attachToSwipeBack(fragmentWalletBinding.getRoot()); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initDataBinding(getArguments()); + } + + private void initDataBinding(Bundle arguments) { + FragmentWalletViewModel fragmentWalletViewModel = new FragmentWalletViewModel(arguments); + fragmentWalletBinding.setFragmentWalletViewModel(fragmentWalletViewModel); + + IBackHandler iBackHandler = new IBackHandler() { + @Override + public void onBack() { + popBackStackFragment(); + } + }; + + fragmentWalletBinding.setBackHandler(iBackHandler); + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/fragments/FragmentWalletAgrement.java b/app/src/main/java/net/iGap/fragments/FragmentWalletAgrement.java new file mode 100644 index 0000000..d666f2d --- /dev/null +++ b/app/src/main/java/net/iGap/fragments/FragmentWalletAgrement.java @@ -0,0 +1,86 @@ +package net.iGap.fragments; + + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.text.Html; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.databinding.FragmentWalletAgrementBinding; +import net.iGap.interfaces.IBackHandler; +import net.iGap.interfaces.OnReceivePageInfoWalletAgreement; +import net.iGap.request.RequestInfoPage; +import net.iGap.viewmodel.FragmentWalletAgreementViewModel; + +/** + * A simple {@link Fragment} subclass. + */ +public class FragmentWalletAgrement extends BaseFragment { + + private FragmentWalletAgrementBinding fragmentWalletAgrementBinding; + private final static String PHONE = "PATH"; + private static String mPhone; + + public static FragmentWalletAgrement newInstance(String phone) { + + Bundle args = new Bundle(); + args.putString(PHONE, phone); + FragmentWalletAgrement fragmentWalletAgrement = new FragmentWalletAgrement(); + fragmentWalletAgrement.setArguments(args); + return fragmentWalletAgrement; + } + + public FragmentWalletAgrement() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentWalletAgrementBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_wallet_agrement, container, false); + return attachToSwipeBack(fragmentWalletAgrementBinding.getRoot()); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initDataBinding(getArguments()); + } + + private void initDataBinding(Bundle arguments) { + IBackHandler iBackHandler = new IBackHandler() { + @Override + public void onBack() { + popBackStackFragment(); + } + }; + + Bundle bundle = getArguments(); + if (bundle != null) { +// path = bundle.getString(PATH); + mPhone = bundle.getString(PHONE); + } + + fragmentWalletAgrementBinding.setBackHandler(iBackHandler); + + FragmentWalletAgreementViewModel fragmentWalletAgreementViewModel = new FragmentWalletAgreementViewModel(fragmentWalletAgrementBinding, mPhone); + fragmentWalletAgrementBinding.setFragmentWalletAgreementViewModel(fragmentWalletAgreementViewModel); + + + G.onReceivePageInfoWalletAgreement = new OnReceivePageInfoWalletAgreement() { + @Override + public void onReceivePageInfo(String body) { + fragmentWalletAgrementBinding.getFragmentWalletAgreementViewModel().callbackTxtAgreement.set(Html.fromHtml(body).toString()); + } + }; + + new RequestInfoPage().infoPage("WALLET_AGREEMENT"); + + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/fragments/FragmentiGapMap.java b/app/src/main/java/net/iGap/fragments/FragmentiGapMap.java index f66bc69..9f97dba 100644 --- a/app/src/main/java/net/iGap/fragments/FragmentiGapMap.java +++ b/app/src/main/java/net/iGap/fragments/FragmentiGapMap.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.fragments; @@ -30,6 +30,7 @@ import android.location.Location; import android.location.LocationManager; import android.media.ThumbnailUtils; +import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.NonNull; @@ -40,6 +41,7 @@ import android.text.Editable; import android.text.TextWatcher; import android.text.format.DateUtils; +import android.util.DisplayMetrics; import android.util.Log; import android.view.GestureDetector; import android.view.Gravity; @@ -47,6 +49,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.LinearLayout; @@ -63,6 +66,7 @@ import net.iGap.G; import net.iGap.R; import net.iGap.activities.ActivityMain; +import net.iGap.adapter.items.chat.ViewMaker; import net.iGap.helper.HelperAvatar; import net.iGap.helper.HelperCalander; import net.iGap.helper.HelperError; @@ -149,7 +153,7 @@ public class FragmentiGapMap extends BaseFragment implements OnLocationChanged, public static RippleView btnBack; public static RippleView rippleMoreMap; public static boolean isBackPress = false; - public static FloatingActionButton fabGps; + public static FloatingActionButton fabGps, fabStateSwitcher; public static Location mineStaticLocation; public static boolean mapRegistrationStatus; public static int page; @@ -202,6 +206,10 @@ public class FragmentiGapMap extends BaseFragment implements OnLocationChanged, private View vgSlideUp; private TextView iconSlide; private boolean isSendRequestGeoCoordinate = false; + private String url; + static boolean changeState = false; + private int orientation = G.rotationState; + private MaterialDialog dialog; public static FragmentiGapMap getInstance() { return new FragmentiGapMap(); @@ -411,11 +419,26 @@ protected static Bitmap addBorderToCircularBitmapSharp(Bitmap srcBitmap, int bor return dstBitmap; } + + public void setTile(final boolean state) { + map.setTileSource(new OnlineTileSourceBase("USGS Topo", ZOOM_LEVEL_MIN, ZOOM_LEVEL_MAX, 256, ".png", new String[]{url}) { + @Override + public String getTileURLString(MapTile aTile) { + if (state) + return "http://mt1.google.com/vt/lyrs=m&hl=fa&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel(); + else + return "http://mt1.google.com/vt/lyrs=y&hl=fa&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel(); + } + }); + } + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { realmMapUsers = Realm.getDefaultInstance(); Configuration.getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context)); + + return inflater.inflate(R.layout.fragment_igap_map, container, false); } @@ -429,13 +452,190 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { G.onGeoGetComment = this; G.onMapUsersGet = this; attentionDialog(); + map = (MapView) view.findViewById(R.id.map); + startMap(view); //clickDrawMarkActive(); + + fabStateSwitcher = (FloatingActionButton) view.findViewById(R.id.st_fab_state); + + fabStateSwitcher.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom))); + fabStateSwitcher.setColorFilter(Color.WHITE); + + fabStateSwitcher.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View view) { + + dialog = new MaterialDialog.Builder(G.fragmentActivity).customView(R.layout.chat_popup_dialog_custom, true).build(); + View v = dialog.getCustomView(); + /* DialogAnimation.animationUp(dialog);*/ + dialog.getWindow().setLayout(ViewMaker.dpToPixel(220), WindowManager.LayoutParams.WRAP_CONTENT); + DisplayMetrics displayMetrics = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + int height = displayMetrics.heightPixels; + int width = displayMetrics.widthPixels; + + WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); + + + if (G.selectedLanguage.equals("en")) { + wmlp.gravity = Gravity.TOP | Gravity.LEFT; + + wmlp.x = ViewMaker.dpToPixel(10); //x position + } else { + wmlp.gravity = Gravity.TOP | Gravity.RIGHT; + wmlp.x = ViewMaker.dpToPixel(10); //x position + } + + + int s = getActivity().getChangingConfigurations(); + + + /* if (orientation==0){ + if (G.isLandscape) + wmlp.y = ViewMaker.dpToPixel(160); + else + wmlp.y = ViewMaker.dpToPixel(400); + + }else */ + if (orientation == 1 || orientation == 0) { + //Do some stuff + wmlp.y = ViewMaker.dpToPixel(400); //y + + } else if (orientation == 2) { + //Do some stuff + wmlp.y = ViewMaker.dpToPixel(160); //y + } + + dialog.show(); + + + ViewGroup root1 = (ViewGroup) v.findViewById(R.id.dialog_root_item1_notification); + ViewGroup root2 = (ViewGroup) v.findViewById(R.id.dialog_root_item2_notification); + ViewGroup root3 = (ViewGroup) v.findViewById(R.id.dialog_root_item3_notification); + + root1.setVisibility(View.GONE); + root2.setVisibility(View.VISIBLE); + root3.setVisibility(View.VISIBLE); + + TextView txtItem1 = (TextView) v.findViewById(R.id.dialog_text_item1_notification); + TextView icon1 = (TextView) v.findViewById(R.id.dialog_icon_item1_notification); + txtItem1.setText(G.fragmentActivity.getResources().getString(R.string.satellite_view)); + icon1.setText(G.fragmentActivity.getResources().getString(R.string.md_nearby)); + + TextView txtItem2 = (TextView) v.findViewById(R.id.dialog_text_item2_notification); + TextView icon2 = (TextView) v.findViewById(R.id.dialog_icon_item2_notification); + txtItem2.setText(G.fragmentActivity.getResources().getString(R.string.default_view)); + icon2.setText(G.fragmentActivity.getResources().getString(R.string.md_map)); + + + TextView txtItem3 = (TextView) v.findViewById(R.id.dialog_text_item3_notification); + TextView icon3 = (TextView) v.findViewById(R.id.dialog_icon_item3_notification); + txtItem3.setText(G.fragmentActivity.getResources().getString(R.string.satellite_view)); + icon3.setText(G.fragmentActivity.getResources().getString(R.string.md_satellite_variant)); + + root1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + fabGps.setVisibility(View.GONE); + fabStateSwitcher.setVisibility(View.GONE); + rippleMoreMap.setVisibility(View.GONE); + page = pageUserList; + try { + new HelperFragment(FragmentMapUsers.newInstance()).setResourceContainer(R.id.mapContainer_main).setReplace(false).load(); + } catch (Exception e) { + e.getStackTrace(); + } + } + }); + + root2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + + + if (isAdded()) { + changeState = getActivity().getSharedPreferences("KEY_SWITCH_MAP_STATE", Context.MODE_PRIVATE) + .getBoolean("state", false); + + + if (changeState) { + deleteMapFileCash(); + getActivity().getSharedPreferences("KEY_SWITCH_MAP_STATE", Context.MODE_PRIVATE).edit().putBoolean("state", false).apply(); + + new HelperFragment(FragmentiGapMap.getInstance()).remove(); + + new HelperFragment(FragmentiGapMap.getInstance()).load(); + } + + } + + } + }); + + root3.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + + dialog.dismiss(); + + deleteMapFileCash(); + if (isAdded()) { + changeState = getActivity().getSharedPreferences("KEY_SWITCH_MAP_STATE", Context.MODE_PRIVATE) + .getBoolean("state", false); + + + if (!changeState) { + deleteMapFileCash(); + getActivity().getSharedPreferences("KEY_SWITCH_MAP_STATE", Context.MODE_PRIVATE).edit().putBoolean("state", true).apply(); + + new HelperFragment(FragmentiGapMap.getInstance()).remove(); + + new HelperFragment(FragmentiGapMap.getInstance()).load(); + } + + } + } + }); + + + + + + + + /* SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + //Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this)); + Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));*/ + + // map.onDetach(); + + /* if (changeState) + changeState = false; + else + changeState = true; + + + map.invalidate(); + + startMap(view);*/ + + + // setTile(false); + + } + }); + + page = 1; new RequestGeoGetComment().getComment(userId); } + private void attentionDialog() { SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); @@ -457,476 +657,503 @@ public void onClick(MaterialDialog dialog, DialogAction which) { } + private void startMap(View view) { - map = (MapView) view.findViewById(R.id.map); //map = new MapView(this); //constructor + // map = (MapView) view.findViewById(R.id.map); // map = new MapView(this); //constructor /** * Set Type Of Map */ - map.setTileSource(TileSourceFactory.MAPNIK); + try { - /** - * Zoom With MultiTouch And With Two Finger - */ - map.setBuiltInZoomControls(false); - map.setMultiTouchControls(true); - /** - * Compass - */ - CompassOverlay mCompassOverlay = new CompassOverlay(getContext(), new InternalCompassOrientationProvider(getContext()), map); - mCompassOverlay.enableCompass(); - map.getOverlays().add(mCompassOverlay); + map.setTileSource(TileSourceFactory.MAPNIK); - /** - * Set Zoom Value - */ - IMapController mapController = map.getController(); - mapController.setZoom(ZOOM_LEVEL_NORMAL); + /** + * Zoom With MultiTouch And With Two Finger + */ + map.setBuiltInZoomControls(false); + map.setMultiTouchControls(true); - /** - * double tap callback enable - */ - final GestureDetector mGestureDetector = new GestureDetector(G.context, this); - map.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - return mGestureDetector.onTouchEvent(event); - } - }); + /** + * Compass + */ + CompassOverlay mCompassOverlay = new CompassOverlay(getContext(), new InternalCompassOrientationProvider(getContext()), map); - /** - * Start With This Point - */ - GeoPoint startPoint = new GeoPoint(35.689197, 51.388974); - mapController.setCenter(startPoint); + mCompassOverlay.enableCompass(); - /** - * Use From Following Code For Custom Url Tile Server - */ - String url; - if (mapUrls.size() > 0) { - url = mapUrls.get(new Random().nextInt(mapUrls.size())); - } else { - Crashlytics.logException(new Exception("FragmentiGapMap -> mapUrls==0; time:" + System.currentTimeMillis())); - url = URL_MAP; - } - map.setTileSource(new OnlineTileSourceBase("USGS Topo", ZOOM_LEVEL_MIN, ZOOM_LEVEL_MAX, 256, ".png", new String[]{url}) { - @Override - public String getTileURLString(MapTile aTile) { - return "http://mt1.google.com/vt/lyrs=m&hl=fa&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel(); - } - }); + map.getOverlays().add(mCompassOverlay); - ViewGroup mapContainer = (ViewGroup) view.findViewById(R.id.mapContainer); - mapContainer.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - } - }); + /** + * Set Zoom Value + */ + IMapController mapController = map.getController(); + mapController.setZoom(ZOOM_LEVEL_NORMAL); - mRecyclerView = (RecyclerView) view.findViewById(R.id.rcy_map_user); - mRecyclerView.setItemAnimator(null); - mRecyclerView.setLayoutManager(new LinearLayoutManager(G.fragmentActivity)); - getRealmMapUsers().executeTransaction(new Realm.Transaction() { - @Override - public void execute(Realm realm) { - realm.where(RealmGeoNearbyDistance.class).findAll().deleteAllFromRealm(); - } - }); - mAdapter = new MapUserAdapter(getRealmMapUsers().where(RealmGeoNearbyDistance.class).findAll(), true); + /** + * double tap callback enable + */ + final GestureDetector mGestureDetector = new GestureDetector(G.context, this); + map.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + return mGestureDetector.onTouchEvent(event); + } + }); + + /** + * Start With This Point + */ + GeoPoint startPoint = new GeoPoint(35.689197, 51.388974); + mapController.setCenter(startPoint); - //fastAdapter - //mAdapter = new MapUserAdapterA(); - mRecyclerView.setAdapter(mAdapter); + /** + * Use From Following Code For Custom Url Tile Server + */ - rootTurnOnGps = (ScrollView) view.findViewById(R.id.scrollView); - rootTurnOnGps.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - //have to empty + if (mapUrls.size() > 0) { + url = mapUrls.get(new Random().nextInt(mapUrls.size())); + } else { + Crashlytics.logException(new Exception("FragmentiGapMap -> mapUrls==0; time:" + System.currentTimeMillis())); + url = URL_MAP; } - }); - vgMessageGps = (ViewGroup) view.findViewById(R.id.vgMessageGps); - txtTextTurnOnOffGps = (TextView) view.findViewById(R.id.txtTextTurnOnOffGps); - txtDescriptionMap = (TextView) view.findViewById(R.id.txtDescriptionMap); - edtMessageGps = (EditText) view.findViewById(R.id.edtMessageGps); + changeState = getActivity().getSharedPreferences("KEY_SWITCH_MAP_STATE", Context.MODE_PRIVATE) + .getBoolean("state", false); - edtMessageGps.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - edtMessageGps.setSingleLine(false); - return false; - } - }); + map.setTileSource(new OnlineTileSourceBase("USGS Topo", ZOOM_LEVEL_MIN, ZOOM_LEVEL_MAX, 256, ".png", new String[]{url}) { + @Override + public String getTileURLString(MapTile aTile) { - prgWaitingGetUser = (ProgressBar) view.findViewById(R.id.prgWaitingGetUser); - prgWaitingGetUserList = (ProgressBar) view.findViewById(R.id.prgWaitingGetUserList); + if (!changeState) + return "http://mt1.google.com/vt/lyrs=m&hl=fa&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel(); + else + return "http://mt1.google.com/vt/lyrs=y&hl=fa&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel(); + } + }); - toggleGps = (ToggleButton) view.findViewById(R.id.toggleGps); - toggleGps.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!isGpsOn) { - try { - startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); - } catch (ActivityNotFoundException e) { - e.printStackTrace(); - } - } else { - new MaterialDialog.Builder(G.fragmentActivity).title(R.string.Visible_Status_title_dialog).content(R.string.Visible_Status_text_dialog).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - if (G.userLogin) { - new RequestGeoRegister().register(true); - } else { - toggleGps.setChecked(false); - showSnackBar(G.fragmentActivity.getResources().getString(R.string.please_check_your_connenction)); - } - } - }).negativeText(R.string.no).onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - toggleGps.setChecked(false); - } - }).show(); + + ViewGroup mapContainer = (ViewGroup) view.findViewById(R.id.mapContainer); + mapContainer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { } + }); - } - }); + mRecyclerView = (RecyclerView) view.findViewById(R.id.rcy_map_user); + mRecyclerView.setItemAnimator(null); + mRecyclerView.setLayoutManager(new LinearLayoutManager(G.fragmentActivity)); + getRealmMapUsers().executeTransaction(new Realm.Transaction() { + @Override + public void execute(Realm realm) { + realm.where(RealmGeoNearbyDistance.class).findAll().deleteAllFromRealm(); + } + }); - prgWaitingSendMessage = (ProgressBar) view.findViewById(R.id.prgWaitSendMessage); - txtSendMessageGps = (TextView) view.findViewById(R.id.txtSendMessageGps); - txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); - if (G.isDarkTheme) { - txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); - } - G.onGeoCommentResponse = new OnGeoCommentResponse() { - @Override - public void commentResponse() { - G.handler.post(new Runnable() { - @Override - public void run() { + mAdapter = new MapUserAdapter(getRealmMapUsers().where(RealmGeoNearbyDistance.class).findAll(), true); + //fastAdapter + //mAdapter = new MapUserAdapterA(); + mRecyclerView.setAdapter(mAdapter); - txtComment = edtMessageGps.getText().toString(); - if (edtMessageGps.length() > 0) { - txtSendMessageGps.setVisibility(View.VISIBLE); - } else { - txtSendMessageGps.setVisibility(View.GONE); - } - prgWaitingSendMessage.setVisibility(View.GONE); - txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); - if (G.isDarkTheme) { - txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); - } - edtMessageGps.setEnabled(true); - } - }); - } + rootTurnOnGps = (ScrollView) view.findViewById(R.id.scrollView); + rootTurnOnGps.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //have to empty + } + }); + vgMessageGps = (ViewGroup) view.findViewById(R.id.vgMessageGps); - @Override - public void errorCommentResponse() { - G.handler.post(new Runnable() { - @Override - public void run() { + txtTextTurnOnOffGps = (TextView) view.findViewById(R.id.txtTextTurnOnOffGps); + txtDescriptionMap = (TextView) view.findViewById(R.id.txtDescriptionMap); + edtMessageGps = (EditText) view.findViewById(R.id.edtMessageGps); - txtSendMessageGps.setVisibility(View.VISIBLE); - prgWaitingSendMessage.setVisibility(View.GONE); - txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); - if (G.isDarkTheme) { - txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); - } - edtMessageGps.setEnabled(true); - } - }); - } + edtMessageGps.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + edtMessageGps.setSingleLine(false); + return false; + } + }); - @Override - public void timeOutCommentResponse() { - G.handler.post(new Runnable() { - @Override - public void run() { + prgWaitingGetUser = (ProgressBar) view.findViewById(R.id.prgWaitingGetUser); + prgWaitingGetUserList = (ProgressBar) view.findViewById(R.id.prgWaitingGetUserList); - txtSendMessageGps.setVisibility(View.VISIBLE); - txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); - if (G.isDarkTheme) { - txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); + toggleGps = (ToggleButton) view.findViewById(R.id.toggleGps); + toggleGps.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (!isGpsOn) { + try { + startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); + } catch (ActivityNotFoundException e) { + e.printStackTrace(); } - prgWaitingSendMessage.setVisibility(View.GONE); - edtMessageGps.setEnabled(true); + } else { + new MaterialDialog.Builder(G.fragmentActivity).title(R.string.Visible_Status_title_dialog).content(R.string.Visible_Status_text_dialog).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + if (G.userLogin) { + new RequestGeoRegister().register(true); + } else { + toggleGps.setChecked(false); + showSnackBar(G.fragmentActivity.getResources().getString(R.string.please_check_your_connenction)); + } + } + }).negativeText(R.string.no).onNegative(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + toggleGps.setChecked(false); + } + }).show(); + } - }); + + } + }); + + prgWaitingSendMessage = (ProgressBar) view.findViewById(R.id.prgWaitSendMessage); + txtSendMessageGps = (TextView) view.findViewById(R.id.txtSendMessageGps); + txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); + if (G.isDarkTheme) { + txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); + } else { + txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); } - }; + G.onGeoCommentResponse = new OnGeoCommentResponse() { + @Override + public void commentResponse() { + G.handler.post(new Runnable() { + @Override + public void run() { - txtSendMessageGps.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + txtComment = edtMessageGps.getText().toString(); + if (edtMessageGps.length() > 0) { + txtSendMessageGps.setVisibility(View.VISIBLE); + } else { + txtSendMessageGps.setVisibility(View.GONE); + } + prgWaitingSendMessage.setVisibility(View.GONE); + txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); + if (G.isDarkTheme) { + txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); + } else { + txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); + } + edtMessageGps.setEnabled(true); + } + }); + } - if (txtSendMessageGps.getText().toString().contains(G.fragmentActivity.getResources().getString(R.string.md_close_button))) { - new MaterialDialog.Builder(G.fragmentActivity).title(R.string.Clear_Status).content(R.string.Clear_Status_desc).positiveText(R.string.st_dialog_reset_all_notification_yes).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void errorCommentResponse() { + G.handler.post(new Runnable() { @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + public void run() { - new RequestGeoUpdateComment().updateComment(""); - edtMessageGps.setText(""); - txtSendMessageGps.setVisibility(View.GONE); + txtSendMessageGps.setVisibility(View.VISIBLE); + prgWaitingSendMessage.setVisibility(View.GONE); txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); if (G.isDarkTheme) { txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); } else { txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); } - + edtMessageGps.setEnabled(true); } - }).negativeText(R.string.st_dialog_reset_all_notification_no).onNegative(new MaterialDialog.SingleButtonCallback() { + }); + } + + @Override + public void timeOutCommentResponse() { + G.handler.post(new Runnable() { @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - } - }).show(); + public void run() { - } else { - txtSendMessageGps.setVisibility(View.GONE); - prgWaitingSendMessage.setVisibility(View.VISIBLE); - edtMessageGps.setEnabled(false); - new RequestGeoUpdateComment().updateComment(edtMessageGps.getText().toString()); + txtSendMessageGps.setVisibility(View.VISIBLE); + txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); + if (G.isDarkTheme) { + txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); + } else { + txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); + } + prgWaitingSendMessage.setVisibility(View.GONE); + edtMessageGps.setEnabled(true); + } + }); } + }; + txtSendMessageGps.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { - //edtMessageGps.setText(""); - } - }); - slidingUpPanelLayout = view.findViewById(R.id.sliding_layout); - vgSlideUp = view.findViewById(R.id.vgSlideUp); - iconSlide = view.findViewById(R.id.ml_user_on_map); - slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() { - @Override - public void onPanelSlide(View panel, float slideOffset) { - vgSlideUp.setAlpha(slideOffset); - if (slideOffset == 1) { - iconSlide.setRotation(180); - } else if (slideOffset == 0) { - iconSlide.setRotation(0); - } - } + if (txtSendMessageGps.getText().toString().contains(G.fragmentActivity.getResources().getString(R.string.md_close_button))) { + new MaterialDialog.Builder(G.fragmentActivity).title(R.string.Clear_Status).content(R.string.Clear_Status_desc).positiveText(R.string.st_dialog_reset_all_notification_yes).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + + new RequestGeoUpdateComment().updateComment(""); + edtMessageGps.setText(""); + txtSendMessageGps.setVisibility(View.GONE); + txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); + if (G.isDarkTheme) { + txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); + } else { + txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); + } + + } + }).negativeText(R.string.st_dialog_reset_all_notification_no).onNegative(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + } + }).show(); - @Override - public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) { - if (newState == SlidingUpPanelLayout.PanelState.DRAGGING && mAdapter != null && mAdapter.getItemCount() == 0) { - if (location != null) { - getDistanceLoop(0, false); } else { - GPSTracker.getGpsTrackerInstance().detectLocation(); + txtSendMessageGps.setVisibility(View.GONE); + prgWaitingSendMessage.setVisibility(View.VISIBLE); + edtMessageGps.setEnabled(false); + new RequestGeoUpdateComment().updateComment(edtMessageGps.getText().toString()); } + + + //edtMessageGps.setText(""); } - } - }); + }); + slidingUpPanelLayout = view.findViewById(R.id.sliding_layout); + vgSlideUp = view.findViewById(R.id.vgSlideUp); + iconSlide = view.findViewById(R.id.ml_user_on_map); + iconSlide.setTextColor(Color.parseColor(G.appBarColor)); + slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() { + @Override + public void onPanelSlide(View panel, float slideOffset) { + vgSlideUp.setAlpha(slideOffset); + if (slideOffset == 1) { + iconSlide.setRotation(180); + } else if (slideOffset == 0) { + iconSlide.setRotation(0); + } + } - final String beforChangeComment = edtMessageGps.getText().toString(); + @Override + public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) { + if (newState == SlidingUpPanelLayout.PanelState.DRAGGING && mAdapter != null && mAdapter.getItemCount() == 0) { + if (location != null) { + getDistanceLoop(0, false); + } else { + GPSTracker.getGpsTrackerInstance().detectLocation(); + } + } + } + }); - edtMessageGps.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } + final String beforChangeComment = edtMessageGps.getText().toString(); - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { + edtMessageGps.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { - if (s.length() > 0) { + if (s.length() > 0) { - if (!txtComment.equals(s.toString())) { - txtSendMessageGps.setVisibility(View.VISIBLE); - txtSendMessageGps.setText(G.context.getString(R.string.md_igap_check)); - if (G.isDarkTheme) { - txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); + if (!txtComment.equals(s.toString())) { + txtSendMessageGps.setVisibility(View.VISIBLE); + txtSendMessageGps.setText(G.context.getString(R.string.md_igap_check)); + if (G.isDarkTheme) { + txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); + } else { + txtSendMessageGps.setTextColor(Color.parseColor(G.appBarColor)); + } } else { - txtSendMessageGps.setTextColor(Color.parseColor(G.appBarColor)); + txtSendMessageGps.setVisibility(View.VISIBLE); + txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); + if (G.isDarkTheme) { + txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); + } else { + txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); + } } } else { - txtSendMessageGps.setVisibility(View.VISIBLE); - txtSendMessageGps.setText(G.context.getString(R.string.md_close_button)); - if (G.isDarkTheme) { - txtSendMessageGps.setTextColor(Color.parseColor(G.textTitleTheme)); - } else { - txtSendMessageGps.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); - } + txtSendMessageGps.setVisibility(View.GONE); } - } else { - txtSendMessageGps.setVisibility(View.GONE); } - } - @Override - public void afterTextChanged(Editable s) { + @Override + public void afterTextChanged(Editable s) { - edtMessageGps.removeTextChangedListener(this); - if (edtMessageGps.getLineCount() > 4) { - edtMessageGps.setText(specialRequests); - //edtMessageGps.setSelection(lastSpecialRequestsCursorPosition); + edtMessageGps.removeTextChangedListener(this); + if (edtMessageGps.getLineCount() > 4) { + edtMessageGps.setText(specialRequests); + //edtMessageGps.setSelection(lastSpecialRequestsCursorPosition); - if (isEndLine) { - isEndLine = false; - showSnackBar(G.fragmentActivity.getResources().getString(R.string.exceed_4_line)); + if (isEndLine) { + isEndLine = false; + showSnackBar(G.fragmentActivity.getResources().getString(R.string.exceed_4_line)); + } + } else { + isEndLine = true; + specialRequests = edtMessageGps.getText().toString(); } - } else { - isEndLine = true; - specialRequests = edtMessageGps.getText().toString(); + + edtMessageGps.addTextChangedListener(this); + } + }); - edtMessageGps.addTextChangedListener(this); + fabGps = (FloatingActionButton) view.findViewById(st_fab_gps); - } - }); - fabGps = (FloatingActionButton) view.findViewById(st_fab_gps); - fabGps.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.appBarColor))); - fabGps.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (location != null) { - currentLocation(location, false); - new RequestGeoUpdatePosition().updatePosition(location.getLatitude(), location.getLongitude()); - } else { - GPSTracker.getGpsTrackerInstance().detectLocation(); - } - } - }); + fabGps.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom))); + fabGps.setColorFilter(Color.WHITE); - view.findViewById(R.id.backgroundToolbarMap).setBackgroundColor(Color.parseColor(G.appBarColor)); - fabGps.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.appBarColor))); - btnBack = (RippleView) view.findViewById(R.id.ripple_back_map); - btnBack.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - // after return to FragmentMapUsers from FragmentContactsProfile don't execute this block - if (G.fragmentManager.getFragments().get(G.fragmentManager.getFragments().size() - 1) != null && G.fragmentManager.getFragments().get(G.fragmentManager.getFragments().size() - 1).getClass().getName().equals(FragmentContactsProfile.class.getName())) { - return; + fabGps.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (location != null) { + currentLocation(location, false); + new RequestGeoUpdatePosition().updatePosition(location.getLatitude(), location.getLongitude()); + } else { + GPSTracker.getGpsTrackerInstance().detectLocation(); + } } + }); - if (rippleMoreMap.getVisibility() == View.GONE || fabGps.getVisibility() == View.GONE) { - rippleMoreMap.setVisibility(View.VISIBLE); - fabGps.setVisibility(View.VISIBLE); - } - if (!isBackPress) { - //getActivity().getSupportFragmentManager().popBackStack(); - G.fragmentActivity.onBackPressed(); + view.findViewById(R.id.backgroundToolbarMap).setBackgroundColor(Color.parseColor(G.appBarColor)); + + btnBack = (RippleView) view.findViewById(R.id.ripple_back_map); + btnBack.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // after return to FragmentMapUsers from FragmentContactsProfile don't execute this block + if (G.fragmentManager.getFragments().get(G.fragmentManager.getFragments().size() - 1) != null && G.fragmentManager.getFragments().get(G.fragmentManager.getFragments().size() - 1).getClass().getName().equals(FragmentContactsProfile.class.getName())) { + return; + } + + if (rippleMoreMap.getVisibility() == View.GONE || fabGps.getVisibility() == View.GONE) { + rippleMoreMap.setVisibility(View.VISIBLE); + fabGps.setVisibility(View.VISIBLE); + fabStateSwitcher.setVisibility(View.VISIBLE); + } + if (!isBackPress) { + //getActivity().getSupportFragmentManager().popBackStack(); + G.fragmentActivity.onBackPressed(); + } + closeKeyboard(v); + isBackPress = false; + page = pageiGapMap; } - closeKeyboard(v); - isBackPress = false; - page = pageiGapMap; - } - }); + }); - rippleMoreMap = (RippleView) view.findViewById(R.id.ripple_more_map); + rippleMoreMap = (RippleView) view.findViewById(R.id.ripple_more_map); - rippleMoreMap.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + rippleMoreMap.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { - final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).customView(R.layout.chat_popup_dialog_custom, true).build(); - View v = dialog.getCustomView(); - DialogAnimation.animationUp(dialog); - dialog.show(); + final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).customView(R.layout.chat_popup_dialog_custom, true).build(); + View v = dialog.getCustomView(); + DialogAnimation.animationUp(dialog); + dialog.show(); - ViewGroup root1 = (ViewGroup) v.findViewById(R.id.dialog_root_item1_notification); - ViewGroup root2 = (ViewGroup) v.findViewById(R.id.dialog_root_item2_notification); - ViewGroup root3 = (ViewGroup) v.findViewById(R.id.dialog_root_item3_notification); + ViewGroup root1 = (ViewGroup) v.findViewById(R.id.dialog_root_item1_notification); + ViewGroup root2 = (ViewGroup) v.findViewById(R.id.dialog_root_item2_notification); + ViewGroup root3 = (ViewGroup) v.findViewById(R.id.dialog_root_item3_notification); - root1.setVisibility(View.GONE); - root2.setVisibility(View.VISIBLE); - root3.setVisibility(View.VISIBLE); + root1.setVisibility(View.GONE); + root2.setVisibility(View.VISIBLE); + root3.setVisibility(View.VISIBLE); - TextView txtItem1 = (TextView) v.findViewById(R.id.dialog_text_item1_notification); - TextView icon1 = (TextView) v.findViewById(R.id.dialog_icon_item1_notification); - txtItem1.setText(G.fragmentActivity.getResources().getString(R.string.list_user_map)); - icon1.setText(G.fragmentActivity.getResources().getString(R.string.md_nearby)); + TextView txtItem1 = (TextView) v.findViewById(R.id.dialog_text_item1_notification); + TextView icon1 = (TextView) v.findViewById(R.id.dialog_icon_item1_notification); + txtItem1.setText(G.fragmentActivity.getResources().getString(R.string.list_user_map)); + icon1.setText(G.fragmentActivity.getResources().getString(R.string.md_nearby)); - TextView txtItem2 = (TextView) v.findViewById(R.id.dialog_text_item2_notification); - TextView icon2 = (TextView) v.findViewById(R.id.dialog_icon_item2_notification); - txtItem2.setText(G.fragmentActivity.getResources().getString(R.string.nearby)); - icon2.setText(G.fragmentActivity.getResources().getString(R.string.md_refresh_button)); + TextView txtItem2 = (TextView) v.findViewById(R.id.dialog_text_item2_notification); + TextView icon2 = (TextView) v.findViewById(R.id.dialog_icon_item2_notification); + txtItem2.setText(G.fragmentActivity.getResources().getString(R.string.nearby)); + icon2.setText(G.fragmentActivity.getResources().getString(R.string.md_refresh_button)); - TextView txtItem3 = (TextView) v.findViewById(R.id.dialog_text_item3_notification); - TextView icon3 = (TextView) v.findViewById(R.id.dialog_icon_item3_notification); - txtItem3.setText(G.fragmentActivity.getResources().getString(R.string.map_registration)); - icon3.setText(G.fragmentActivity.getResources().getString(R.string.md_igap_map_marker_off)); + TextView txtItem3 = (TextView) v.findViewById(R.id.dialog_text_item3_notification); + TextView icon3 = (TextView) v.findViewById(R.id.dialog_icon_item3_notification); + txtItem3.setText(G.fragmentActivity.getResources().getString(R.string.map_registration)); + icon3.setText(G.fragmentActivity.getResources().getString(R.string.md_igap_map_marker_off)); - root1.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dialog.dismiss(); - fabGps.setVisibility(View.GONE); - rippleMoreMap.setVisibility(View.GONE); - page = pageUserList; - try { - new HelperFragment(FragmentMapUsers.newInstance()).setResourceContainer(R.id.mapContainer_main).setReplace(false).load(); - } catch (Exception e) { - e.getStackTrace(); + root1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + fabGps.setVisibility(View.GONE); + fabStateSwitcher.setVisibility(View.GONE); + rippleMoreMap.setVisibility(View.GONE); + page = pageUserList; + try { + new HelperFragment(FragmentMapUsers.newInstance()).setResourceContainer(R.id.mapContainer_main).setReplace(false).load(); + } catch (Exception e) { + e.getStackTrace(); + } } - } - }); + }); - root2.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dialog.dismiss(); + root2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + + if (location != null && !isSendRequestGeoCoordinate) { + new RequestGeoGetNearbyCoordinate().getNearbyCoordinate(location.getLatitude(), location.getLongitude()); + showProgress(true); + isSendRequestGeoCoordinate = true; + } - if (location != null && !isSendRequestGeoCoordinate) { - new RequestGeoGetNearbyCoordinate().getNearbyCoordinate(location.getLatitude(), location.getLongitude()); - showProgress(true); - isSendRequestGeoCoordinate = true; } + }); - } - }); + root3.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); - root3.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dialog.dismiss(); + new MaterialDialog.Builder(G.fragmentActivity).title(R.string.Visible_Status_title_dialog_invisible).content(R.string.Visible_Status_text_dialog_invisible).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - new MaterialDialog.Builder(G.fragmentActivity).title(R.string.Visible_Status_title_dialog_invisible).content(R.string.Visible_Status_text_dialog_invisible).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + new RequestGeoRegister().register(false); - new RequestGeoRegister().register(false); + } + }).negativeText(R.string.no).onNegative(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - } - }).negativeText(R.string.no).onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + } + }).show(); + } + }); + } + }); - } - }).show(); - } - }); + if (FragmentiGapMap.mineStaticLocation != null) { + GPSTracker.getGpsTrackerInstance().onLocationChanged(FragmentiGapMap.mineStaticLocation); } - }); - if (FragmentiGapMap.mineStaticLocation != null) { - GPSTracker.getGpsTrackerInstance().onLocationChanged(FragmentiGapMap.mineStaticLocation); + } catch (Exception e) { } } @@ -1312,6 +1539,7 @@ public void statusCheck() { if (mapRegistrationStatus) { rootTurnOnGps.setVisibility(View.GONE); fabGps.setVisibility(View.VISIBLE); + fabStateSwitcher.setVisibility(View.VISIBLE); vgMessageGps.setVisibility(View.VISIBLE); rippleMoreMap.setVisibility(View.VISIBLE); GPSTracker.getGpsTrackerInstance().detectLocation(); @@ -1328,6 +1556,7 @@ public void statusCheck() { private void visibleViewAttention(String text, boolean b) { rootTurnOnGps.setVisibility(View.VISIBLE); fabGps.setVisibility(View.GONE); + fabStateSwitcher.setVisibility(View.GONE); toggleGps.setChecked(false); vgMessageGps.setVisibility(View.GONE); rippleMoreMap.setVisibility(View.GONE); @@ -1355,6 +1584,15 @@ public void onResume() { @Override public void onConfigurationChanged(android.content.res.Configuration newConfig) { super.onConfigurationChanged(newConfig); + + try { + dialog.dismiss(); + } catch (Exception e) { + } + + orientation = newConfig.orientation; + + G.handler.postDelayed(new Runnable() { @Override public void run() { @@ -1649,4 +1887,6 @@ public ViewHolder(View itemView) { } } } + + } diff --git a/app/src/main/java/net/iGap/fragments/RegisteredContactsFragment.java b/app/src/main/java/net/iGap/fragments/RegisteredContactsFragment.java index 6a0194a..f810ee2 100644 --- a/app/src/main/java/net/iGap/fragments/RegisteredContactsFragment.java +++ b/app/src/main/java/net/iGap/fragments/RegisteredContactsFragment.java @@ -68,6 +68,7 @@ import net.iGap.module.AndroidUtils; import net.iGap.module.AppUtils; import net.iGap.module.CircleImageView; +import net.iGap.module.ContactUtils; import net.iGap.module.Contacts; import net.iGap.module.CustomTextViewMedium; import net.iGap.module.LastSeenTimeUtil; @@ -222,6 +223,7 @@ public void onViewCreated(View view, final @Nullable Bundle savedInstanceState) final RippleView txtClose = (RippleView) view.findViewById(R.id.menu_ripple_close); edtSearch = (EditText) view.findViewById(R.id.menu_edt_search); final TextView txtSearch = (TextView) view.findViewById(R.id.menu_btn_search); + final TextView txtSync = (TextView) view.findViewById(R.id.menu_btn_sync); txtSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -230,6 +232,7 @@ public void onClick(View v) { edtSearch.setFocusable(true); menu_txt_titleToolbar.setVisibility(View.GONE); txtSearch.setVisibility(View.GONE); + txtSync.setVisibility(View.GONE); } }); @@ -243,6 +246,7 @@ public void onClick(View v) { edtSearch.setVisibility(View.GONE); menu_txt_titleToolbar.setVisibility(View.VISIBLE); txtSearch.setVisibility(View.VISIBLE); + txtSync.setVisibility(View.VISIBLE); InputMethodManager imm = (InputMethodManager) G.fragmentActivity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } @@ -309,6 +313,14 @@ public void onComplete(RippleView rippleView) { } }); + RippleView rippleSync = (RippleView) view.findViewById(R.id.menu_sync); + rippleSync.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() { + @Override + public void onComplete(RippleView rippleView) { + ContactUtils.syncContacts(); + } + }); + realmRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); realmRecyclerView.setItemViewCacheSize(1000); realmRecyclerView.setItemAnimator(null); @@ -497,7 +509,6 @@ public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int old } - private void hideProgress() { G.handler.post(new Runnable() { @@ -996,10 +1007,7 @@ public void onClick(View v) { @Override public void complete() { hideProgress(); - // G.fragmentActivity.getSupportFragmentManager().beginTransaction().remove(RegisteredContactsFragment.this).commit(); - popBackStackFragment(); - } }, new HelperPublicMethod.OnError() { @Override @@ -1104,17 +1112,17 @@ public void onClick(View v) { .content(G.fragmentActivity.getResources().getString(R.string.invite_friend)) .positiveText(G.fragmentActivity.getResources().getString(R.string.ok)).negativeText(G.fragmentActivity.getResources().getString(R.string.cancel)) .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - - Intent sendIntent = new Intent(); - sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, "Hey Join iGap : https://www.igap.net/ I'm waiting for you!"); - sendIntent.setType("text/plain"); - sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - G.context.startActivity(sendIntent); - } - }).show(); + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, "Hey Join iGap : https://www.igap.net/ I'm waiting for you!"); + sendIntent.setType("text/plain"); + sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + G.context.startActivity(sendIntent); + } + }).show(); } diff --git a/app/src/main/java/net/iGap/helper/Emojione.java b/app/src/main/java/net/iGap/helper/Emojione.java index 121be54..05078a6 100644 --- a/app/src/main/java/net/iGap/helper/Emojione.java +++ b/app/src/main/java/net/iGap/helper/Emojione.java @@ -11,11 +11,13 @@ import android.os.Build; +import com.vanniktech.emoji.EmojiProvider; + import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -public abstract class Emojione { +public abstract class Emojione implements EmojiProvider { private static final HashMap _shortNameToUnicode = new HashMap<>(); private static final Pattern SHORTNAME_PATTERN = Pattern.compile(":([-+\\w]+):"); diff --git a/app/src/main/java/net/iGap/helper/HelperAddContact.java b/app/src/main/java/net/iGap/helper/HelperAddContact.java index 38ec118..f4d8229 100644 --- a/app/src/main/java/net/iGap/helper/HelperAddContact.java +++ b/app/src/main/java/net/iGap/helper/HelperAddContact.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.helper; @@ -21,6 +21,10 @@ public class HelperAddContact { public static void addContact(String displayName, String codeNumber, String phone) { + if (phone == null) { + return; + } + String saveNumber; if (phone.startsWith("0")) { saveNumber = codeNumber + phone.substring(1, phone.length()); @@ -30,11 +34,6 @@ public static void addContact(String displayName, String codeNumber, String phon ArrayList ops = new ArrayList(); - ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) - .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null) - .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null) - .build()); - //------------------------------------------------------ Names if (displayName != null) { ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) @@ -44,15 +43,13 @@ public static void addContact(String displayName, String codeNumber, String phon .build()); } //------------------------------------------------------ Mobile Number - if (phone != null) { - ops.add(ContentProviderOperation. - newInsert(ContactsContract.Data.CONTENT_URI) - .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) - .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) - .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, saveNumber) - .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE) - .build()); - } + ops.add(ContentProviderOperation. + newInsert(ContactsContract.Data.CONTENT_URI) + .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) + .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) + .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, saveNumber) + .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE) + .build()); try { G.context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); diff --git a/app/src/main/java/net/iGap/helper/HelperCalander.java b/app/src/main/java/net/iGap/helper/HelperCalander.java index 7193431..8476e82 100644 --- a/app/src/main/java/net/iGap/helper/HelperCalander.java +++ b/app/src/main/java/net/iGap/helper/HelperCalander.java @@ -380,7 +380,7 @@ public static String getClocktime(Long timeinMili, boolean ltr) { String result; if (G.isTimeWhole){ - result = TimeUtils.toLocal(timeinMili, "kk:mm"); + result = TimeUtils.toLocal(timeinMili, "HH:mm"); }else if (HelperCalander.isPersianUnicode) { result = TimeUtils.toLocal(timeinMili, "h:mm a"); String[] _date = result.split(" "); diff --git a/app/src/main/java/net/iGap/helper/HelperDownloadFile.java b/app/src/main/java/net/iGap/helper/HelperDownloadFile.java index b85bb5b..4b7b389 100644 --- a/app/src/main/java/net/iGap/helper/HelperDownloadFile.java +++ b/app/src/main/java/net/iGap/helper/HelperDownloadFile.java @@ -10,6 +10,8 @@ package net.iGap.helper; +import android.os.Handler; +import android.os.Looper; import android.support.annotation.NonNull; import android.support.v4.util.ArrayMap; @@ -36,7 +38,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.ConcurrentModificationException; -import java.util.Iterator; import java.util.Map; import io.realm.Realm; @@ -44,141 +45,39 @@ public class HelperDownloadFile { - public static ArrayList manuallyStoppedDownload = new ArrayList<>(); - private static ArrayMap list = new ArrayMap<>(); - private static ArrayList mQueue = new ArrayList<>(); - private static int maxDownloadSize = 2; - private OnFileDownloadResponse onFileDownloadResponse; - - - public HelperDownloadFile() { - - onFileDownloadResponse = new OnFileDownloadResponse() { - @Override - public void onFileDownload(String cashId, long offset, ProtoFileDownload.FileDownload.Selector selector, int progress) { - - finishDownload(cashId, offset, selector, progress); - - } - - @Override - public void onError(int majorCode, int minorCode, String cashId, ProtoFileDownload.FileDownload.Selector selector) { - errorDownload(cashId, selector); - } - }; - - G.onFileDownloadResponse = onFileDownloadResponse; - } - - private static void errorDownload(String cashId, ProtoFileDownload.FileDownload.Selector selector) { - String primaryKey = cashId + selector; - - if (list.size() > 0 && list.containsKey(primaryKey)) { - StructDownLoad item = list.get(primaryKey); - - item.attampOnError--; - if (item.attampOnError >= 0) { - requestDownloadFile(item); - } else { - - for (StructListener mItem : item.structListeners) { - if (mItem.listener != null) { - mItem.listener.OnError(item.Token); - } - } - - list.remove(primaryKey); - - // if (selector == ProtoFileDownload.FileDownload.Selector.FILE) { - addDownloadFromQueue(); - // } - } - } - } - - private static void finishDownload(String cashId, long offset, ProtoFileDownload.FileDownload.Selector selector, int progress) { - String PrimaryKey = cashId + selector; - - if (list.size() > 0 && list.containsKey(PrimaryKey)) { - StructDownLoad item = list.get(PrimaryKey); - item.offset = offset; - item.progress = progress; - - if (item.selector == ProtoFileDownload.FileDownload.Selector.FILE) { - - if (mQueue.size() > 0) { - if (mQueue.get(0).priority > item.priority) { - - if (item.priority < 3) { - ++item.priority; - } - - addItemToQueue(item.cashId + item.selector, item.priority); - addDownloadFromQueue(); - return; - } - } - } + public interface UpdateListener { + void OnProgress(String path, int progress); - requestDownloadFile(item); - } + void OnError(String token); } + public class StructListener { + public UpdateListener listener; + public String messageId; - private static boolean isNeedItemGoToQueue() { - - if (mQueue.size() > 0 || list.size() > maxDownloadSize) { - return true; - } - - return false; - - - /* int count = 0; - - for (int i = 0; i < list.size(); i++) { - - StructDownLoad _sd = list.valueAt(i); - // if (_sd.selector == ProtoFileDownload.FileDownload.Selector.FILE){ - count++; - // } + StructListener(UpdateListener listener, String messageId) { + this.listener = listener; + this.messageId = messageId; } - - if ((count) > maxDownloadSize) return true; - - return false;*/ } - private static void addItemToQueue(String primaryKey, int priority) { + private static HelperDownloadFile helperDownloadFile; + public ArrayList manuallyStoppedDownload = new ArrayList<>(); + private ArrayMap list = new ArrayMap<>(); + private ArrayList mQueue = new ArrayList<>(); + private Handler handler; + private final static int maxDownloadSize = 4; - boolean additem = false; - - StructQueue sq = new StructQueue(); - sq.priority = priority; - sq.primaryKey = primaryKey; + //********************************************************************************************** - for (int i = mQueue.size() - 1; i >= 0; i--) { - try { - if (priority > mQueue.get(i).priority) { - continue; - } else { - if (mQueue.size() >= (i + 1)) { - mQueue.add(i + 1, sq); - additem = true; - break; - } - } - } catch (NullPointerException | IndexOutOfBoundsException e) { - e.printStackTrace(); - } - } - - if (!additem) { - mQueue.add(0, sq); + public static HelperDownloadFile getInstance() { + if (helperDownloadFile == null) { + helperDownloadFile = new HelperDownloadFile(); } + return helperDownloadFile; } - public static void startDownload(String messageID, String token, String url, String cashId, String name, long size, ProtoFileDownload.FileDownload.Selector selector, String moveToDirectoryPAth, int periority, UpdateListener update) { + public void startDownload(String messageID, String token, String url, String cashId, String name, long size, ProtoFileDownload.FileDownload.Selector selector, String moveToDirectoryPAth, int periority, UpdateListener update) { StructDownLoad item; String primaryKey = cashId + selector; @@ -282,8 +181,7 @@ public static void startDownload(String messageID, String token, String url, Str } - - public static void stopDownLoad(String cacheId) { + public void stopDownLoad(String cacheId) { manuallyStoppedDownload.add(cacheId); String primaryKey = cacheId + ProtoFileDownload.FileDownload.Selector.FILE; @@ -298,7 +196,7 @@ public static void stopDownLoad(String cacheId) { } - if (item != null && item.structListeners != null) { + if (item.structListeners != null) { for (StructListener mItem : item.structListeners) { if (mItem.listener != null) { item.isPause = true; @@ -312,7 +210,153 @@ public static void stopDownLoad(String cacheId) { } } - private static void addDownloadFromQueue() { + public boolean isDownLoading(String cashID) { + String primaryKey = cashID + ProtoFileDownload.FileDownload.Selector.FILE; + return list.containsKey(primaryKey); + } + + //********************************************************************************************** + + private void getHandler() { + + new Thread(new Runnable() { + @Override + public void run() { + Looper.prepare(); + + if (handler == null) { + handler = new Handler(); + } + + Looper.loop(); + } + }).start(); + + } + + private HelperDownloadFile() { + + getHandler(); + + G.onFileDownloadResponse = new OnFileDownloadResponse() { + @Override + public void onFileDownload(String cashId, long offset, ProtoFileDownload.FileDownload.Selector selector, int progress) { + + finishDownload(cashId, offset, selector, progress); + + } + + @Override + public void onError(int majorCode, int minorCode, String cashId, ProtoFileDownload.FileDownload.Selector selector) { + errorDownload(cashId, selector); + } + }; + + + } + + private void errorDownload(String cashId, ProtoFileDownload.FileDownload.Selector selector) { + String primaryKey = cashId + selector; + + if (list.size() > 0 && list.containsKey(primaryKey)) { + StructDownLoad item = list.get(primaryKey); + + item.attampOnError--; + if (item.attampOnError >= 0) { + requestDownloadFile(item); + } else { + + for (StructListener mItem : item.structListeners) { + if (mItem.listener != null) { + mItem.listener.OnError(item.Token); + } + } + + list.remove(primaryKey); + + // if (selector == ProtoFileDownload.FileDownload.Selector.FILE) { + addDownloadFromQueue(); + // } + } + } + } + + private void finishDownload(String cashId, long offset, ProtoFileDownload.FileDownload.Selector selector, int progress) { + String PrimaryKey = cashId + selector; + + if (list.size() > 0 && list.containsKey(PrimaryKey)) { + StructDownLoad item = list.get(PrimaryKey); + item.offset = offset; + item.progress = progress; + + if (item.selector == ProtoFileDownload.FileDownload.Selector.FILE) { + + if (mQueue.size() > 0) { + if (mQueue.get(0).priority > item.priority) { + + if (item.priority < 3) { + ++item.priority; + } + + addItemToQueue(item.cashId + item.selector, item.priority); + addDownloadFromQueue(); + return; + } + } + } + + requestDownloadFile(item); + } + } + + private boolean isNeedItemGoToQueue() { + + return mQueue.size() > 0 || list.size() > maxDownloadSize; + + + /* int count = 0; + + for (int i = 0; i < list.size(); i++) { + + StructDownLoad _sd = list.valueAt(i); + // if (_sd.selector == ProtoFileDownload.FileDownload.Selector.FILE){ + count++; + // } + } + + if ((count) > maxDownloadSize) return true; + + return false;*/ + } + + private void addItemToQueue(String primaryKey, int priority) { + + boolean additem = false; + + StructQueue sq = new StructQueue(); + sq.priority = priority; + sq.primaryKey = primaryKey; + + for (int i = mQueue.size() - 1; i >= 0; i--) { + try { + if (priority <= mQueue.get(i).priority) { + if (mQueue.size() >= (i + 1)) { + mQueue.add(i + 1, sq); + additem = true; + break; + } + } + } catch (NullPointerException | IndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + + if (!additem) { + mQueue.add(0, sq); + } + } + + private void addDownloadFromQueue() { // if any file exist in download queue add one to start download @@ -329,8 +373,7 @@ private static void addDownloadFromQueue() { } } - - private static void startDownloadManager(final StructDownLoad item) { + private void startDownloadManager(final StructDownLoad item) { item.path = Utils.getTempPath(item.path, item.name); final String path = item.path.replace("/" + new File(item.path).getName(), ""); @@ -368,7 +411,17 @@ public void onProgress(Progress progress) { .start(new OnDownloadListener() { @Override public void onDownloadComplete() { - finishDownload(item.cashId, item.offset, item.selector, item.progress); + + try { + handler.post(new Runnable() { + @Override + public void run() { + finishDownload(item.cashId, item.offset, item.selector, item.progress); + } + }); + } catch (NullPointerException e) { + HelperLog.setErrorLog("HelperDownloadFile startDownloadManager onDownloadComplete " + e.toString()); + } } @Override @@ -378,7 +431,7 @@ public void onError(Error error) { }); } - private static void requestDownloadFile(final StructDownLoad item) { + private void requestDownloadFile(final StructDownLoad item) { manuallyStoppedDownload.remove(item.cashId); if (item.progress == 100 || item.offset >= item.size) { @@ -410,7 +463,7 @@ private static void requestDownloadFile(final StructDownLoad item) { } } - private static void moveTmpFileToOrginFolder(ProtoFileDownload.FileDownload.Selector selector, String cashId) { + private void moveTmpFileToOrginFolder(ProtoFileDownload.FileDownload.Selector selector, String cashId) { StructDownLoad item = list.get(cashId + selector); @@ -438,7 +491,7 @@ private static void moveTmpFileToOrginFolder(ProtoFileDownload.FileDownload.Sele } } - private static void setThumbnailPathDataBaseAttachment(final String cashID, final String path) { + private void setThumbnailPathDataBaseAttachment(final String cashID, final String path) { Realm realm = Realm.getDefaultInstance(); realm.executeTransaction(new Realm.Transaction() { @@ -454,12 +507,7 @@ public void execute(@NonNull Realm realm) { realm.close(); } - public static boolean isDownLoading(String cashID) { - String primaryKey = cashID + ProtoFileDownload.FileDownload.Selector.FILE; - return list.containsKey(primaryKey); - } - - private static void setFilePAthToDataBaseAttachment(final String cashID, final String path) { + private void setFilePAthToDataBaseAttachment(final String cashID, final String path) { Realm realm = Realm.getDefaultInstance(); realm.executeTransaction(new Realm.Transaction() { @@ -475,7 +523,7 @@ public void execute(Realm realm) { realm.close(); } - private static void updateView(final StructDownLoad item) { + private void updateView(final StructDownLoad item) { for (StructListener mItem : item.structListeners) { if (mItem.listener != null) { String _path = item.moveToDirectoryPAth.length() > 0 ? item.moveToDirectoryPAth : item.path; @@ -484,55 +532,35 @@ private static void updateView(final StructDownLoad item) { } } - public static boolean removeRequestQueue(String identity) { - for (Iterator> it = G.requestQueueMap.entrySet().iterator(); it.hasNext(); ) { - Map.Entry entry = it.next(); - + void removeRequestQueue(String identity) { + for (Map.Entry entry : G.requestQueueMap.entrySet()) { if (entry.getValue().identity != null && entry.getValue().identity.toString().contains(identity)) { G.requestQueueMap.remove(entry.getKey()); - return true; } } - return false; - } - - public interface UpdateListener { - void OnProgress(String path, int progress); - - void OnError(String token); - } - - public static class StructListener { - public UpdateListener listener; - public String messageId; - - public StructListener(UpdateListener listener, String messageId) { - this.listener = listener; - this.messageId = messageId; - } } - private static class StructDownLoad { + private class StructDownLoad { - public String Token = ""; + String Token = ""; public String url = ""; - public int idDownload = 0; - public String cashId = ""; - public ArrayList structListeners = new ArrayList<>(); + int idDownload = 0; + String cashId = ""; + ArrayList structListeners = new ArrayList<>(); public int progress = 0; public long offset = 0; public String name = ""; - public String moveToDirectoryPAth = ""; + String moveToDirectoryPAth = ""; public long size = 0; public String identity = ""; - public int attampOnError = 2; + int attampOnError = 2; public ProtoFileDownload.FileDownload.Selector selector; public String path = ""; - public int priority = 0; - public boolean isPause = false; + int priority = 0; + boolean isPause = false; } - private static class StructQueue { + private class StructQueue { String primaryKey; int priority; } diff --git a/app/src/main/java/net/iGap/helper/HelperError.java b/app/src/main/java/net/iGap/helper/HelperError.java index 46cb030..1a8a50f 100644 --- a/app/src/main/java/net/iGap/helper/HelperError.java +++ b/app/src/main/java/net/iGap/helper/HelperError.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.helper; @@ -488,6 +488,47 @@ public static String getErrorFromCode(int majorCode, int minorCode) { error = G.fragmentActivity.getResources().getString(R.string.E_715); break; + case 9001: + //error = G.fragmentActivity.getResources().getString(R.string.E_9001); + break; + case 9002: + error = G.fragmentActivity.getResources().getString(R.string.E_9002); + break; + case 9003: + //error = G.fragmentActivity.getResources().getString(R.string.E_9003); + break; + case 9004: + //error = G.fragmentActivity.getResources().getString(R.string.E_9004); + break; + case 9005: + //error = G.fragmentActivity.getResources().getString(R.string.E_9005); + break; + case 9006: + error = G.fragmentActivity.getResources().getString(R.string.E_9006); + break; + case 9007: + error = G.fragmentActivity.getResources().getString(R.string.E_9007); + break; + case 9008: + error = G.fragmentActivity.getResources().getString(R.string.E_9008); + break; + case 9009: + error = G.fragmentActivity.getResources().getString(R.string.E_9009); + break; + case 9010: + error = G.fragmentActivity.getResources().getString(R.string.E_9010); + break; + case 9011: + //error = G.fragmentActivity.getResources().getString(R.string.E_9011); + break; + case 9012: + //error = G.fragmentActivity.getResources().getString(R.string.E_9012); + break; + case 9013: + error = G.fragmentActivity.getResources().getString(R.string.E_9013); + break; + + case 10105: if (minorCode == 101) { error = G.fragmentActivity.getResources().getString(R.string.E_713_1); diff --git a/app/src/main/java/net/iGap/helper/HelperFillLookUpClass.java b/app/src/main/java/net/iGap/helper/HelperFillLookUpClass.java index 254f75a..4cb8305 100644 --- a/app/src/main/java/net/iGap/helper/HelperFillLookUpClass.java +++ b/app/src/main/java/net/iGap/helper/HelperFillLookUpClass.java @@ -10,7 +10,6 @@ package net.iGap.helper; -import net.iGap.fragments.FragmentQrCodeNewDevice; import net.iGap.fragments.FragmentShowAvatars; import net.iGap.fragments.FragmentShowImage; @@ -197,6 +196,7 @@ private static void fillLookUpClassArray() { lookupMap.put(30614, "ProtoClientMuteRoom.ClientMuteRoomResponse"); lookupMap.put(30615, "ProtoClientPinRoom.ClientPinRoomResponse"); lookupMap.put(30616, "ProtoClientRoomReport.ClientRoomReportResponse"); + lookupMap.put(30617, "ProtoClientRegisterDevice.ClientRegisterDeviceResponse"); // FileUpload,Download 7xx , 307xx lookupMap.put(30700, "ProtoFileUploadOption.FileUploadOptionResponse"); @@ -235,11 +235,24 @@ private static void fillLookUpClassArray() { lookupMap.put(31006, "ProtoGeoGetNearbyCoordinate.GeoGetNearbyCoordinateResponse"); lookupMap.put(31007, "ProtoGeoGetConfiguration.GeoGetConfigurationResponse"); + //Wallet 90xx + lookupMap.put(39000, "ProtoWalletGetAccessToken.WalletGetAccessTokenResponse"); + lookupMap.put(39001, "ProtoWalletPaymentInit.WalletPaymentInitResponse"); + lookupMap.put(39002, "ProtoWalletRegister.WalletRegisterResponse"); + lookupMap.put(39003, "ProtoWalletIdMapping.WalletIdMappingResponse"); + + //Mpl 90xx + lookupMap.put(39100, "ProtoMplGetBillToken.MplGetBillTokenResponse"); + lookupMap.put(39101, "ProtoMplGetTopupToken.MplGetTopupTokenResponse"); + lookupMap.put(39200, "ProtoBillInquiryMci.BillInquiryMciResponse"); + lookupMap.put(39201, "ProtoBillInquiryTelecom.BillInquiryTelecomResponse"); + // Push 600xx lookupMap.put(60000, "ProtoPushLoginToken.PushLoginTokenResponse"); lookupMap.put(60001, "ProtoPushTwoStepVerification.PushTwoStepVerificationResponse"); lookupMap.put(60002, "ProtoPushUserInfoExpired.PushUserInfoExpiredResponse"); lookupMap.put(60003, "ProtoPushRateSignaling.PushRateSignalingResponse"); + lookupMap.put(60004, "ProtoPushWalletPaymentVerified.PushWalletPaymentVerifiedResponse"); } @@ -287,7 +300,6 @@ private static void fillUnLoginList() { private static void fillImmovableClasses() { generalImmovableClasses.add(FragmentShowAvatars.class.getName()); generalImmovableClasses.add(FragmentShowImage.class.getName()); - generalImmovableClasses.add(FragmentQrCodeNewDevice.class.getName()); } /** diff --git a/app/src/main/java/net/iGap/helper/HelperFragment.java b/app/src/main/java/net/iGap/helper/HelperFragment.java index 157906a..eeff411 100644 --- a/app/src/main/java/net/iGap/helper/HelperFragment.java +++ b/app/src/main/java/net/iGap/helper/HelperFragment.java @@ -43,12 +43,12 @@ public HelperFragment(Fragment fragment) { this.fragment = fragment; } - public static Fragment isFragmentVisible(String fragmentTag) { + public static boolean isFragmentVisible(String fragmentTag) { Fragment fragment = G.fragmentActivity.getSupportFragmentManager().findFragmentByTag(fragmentTag); - if (fragment != null && fragment.isVisible()) { - return fragment; + if (fragment != null) { + return fragment.isVisible(); } - return null; + return false; } public static Fragment isFragmentVisible(ArrayList fragmentTags) { diff --git a/app/src/main/java/net/iGap/helper/HelperImageBackColor.java b/app/src/main/java/net/iGap/helper/HelperImageBackColor.java index 38874d1..87c4ad6 100644 --- a/app/src/main/java/net/iGap/helper/HelperImageBackColor.java +++ b/app/src/main/java/net/iGap/helper/HelperImageBackColor.java @@ -98,20 +98,25 @@ public static Bitmap drawAlphabetOnPicture(int with, String text, String color) p.setDither(true); p.setAntiAlias(true); p.setColor(Color.parseColor(color)); - Canvas c = new Canvas(bitmap); - c.drawCircle(with / 2, with / 2, with / 2, p); - - int fontSize = with / 3; - Canvas cs = new Canvas(bitmap); - - Paint textPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); - textPaint.setMaskFilter(new BlurMaskFilter(1, BlurMaskFilter.Blur.SOLID)); - textPaint.setColor(Color.parseColor(mColor)); - textPaint.setTextAlign(Paint.Align.CENTER); - textPaint.setTextSize(fontSize); - textPaint.setTypeface(G.typeface_IRANSansMobile_Bold); - textPaint.setStyle(Paint.Style.FILL); - cs.drawText(alphabetName, with / 2, with / 2 + fontSize / 4, textPaint); + + try { + Canvas c = new Canvas(bitmap); + c.drawCircle(with / 2, with / 2, with / 2, p); + + int fontSize = with / 3; + Canvas cs = new Canvas(bitmap); + + Paint textPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); + textPaint.setMaskFilter(new BlurMaskFilter(1, BlurMaskFilter.Blur.SOLID)); + textPaint.setColor(Color.parseColor(mColor)); + textPaint.setTextAlign(Paint.Align.CENTER); + textPaint.setTextSize(fontSize); + textPaint.setTypeface(G.typeface_IRANSansMobile_Bold); + textPaint.setStyle(Paint.Style.FILL); + cs.drawText(alphabetName, with / 2, with / 2 + fontSize / 4, textPaint); + } catch (NullPointerException e) { + HelperLog.setErrorLog("HelperImageBackColor drawAlphabetOnPicture " + e); + } return bitmap; } diff --git a/app/src/main/java/net/iGap/helper/HelperMessageResponse.java b/app/src/main/java/net/iGap/helper/HelperMessageResponse.java index 83bb5a4..5e5cdd9 100644 --- a/app/src/main/java/net/iGap/helper/HelperMessageResponse.java +++ b/app/src/main/java/net/iGap/helper/HelperMessageResponse.java @@ -90,9 +90,9 @@ public void execute(Realm realm) { room.setUnreadCount(room.getUnreadCount() + 1); if (!room.getMute()) { - if (G.isAppInFg || AttachFile.isInAttach) { - // HelperNotificationAndBadge.updateBadgeOnly(realm,-1); - } else { +// if (G.isAppInFg || AttachFile.isInAttach) { +// // HelperNotificationAndBadge.updateBadgeOnly(realm,-1); +// } else { if (roomType != ProtoGlobal.Room.Type.CHANNEL) { G.handler.postDelayed(new Runnable() { @@ -110,7 +110,7 @@ public void run() { }, 200); } - } +// } } diff --git a/app/src/main/java/net/iGap/helper/HelperNotificationAndBadge.java b/app/src/main/java/net/iGap/helper/HelperNotificationAndBadge.java index 3bc06c2..f3797e4 100644 --- a/app/src/main/java/net/iGap/helper/HelperNotificationAndBadge.java +++ b/app/src/main/java/net/iGap/helper/HelperNotificationAndBadge.java @@ -12,6 +12,7 @@ import android.app.ActivityManager; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -98,6 +99,7 @@ public class HelperNotificationAndBadge { private String mHeader = ""; private String mContent = ""; private Bitmap mBitmapIcon = null; + String CHANNEL_ID = "iGap_channel_01"; public HelperNotificationAndBadge() { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); @@ -108,6 +110,14 @@ public HelperNotificationAndBadge() { intentClose.putExtra("Action", "strClose"); PendingIntent pendingIntentClose = PendingIntent.getBroadcast(context, 1, intentClose, 0); remoteViewsLarge.setOnClickPendingIntent(R.id.mln_btn_close, pendingIntentClose); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // The id of the channel. + CharSequence name = G.context.getString(R.string.channel_name_notification);// The user-visible name of the channel. + int importance = NotificationManager.IMPORTANCE_DEFAULT; + NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance); + notificationManager.createNotificationChannel(mChannel); + } } //private void setOnTextClick(int resLayot, int indexItem) { @@ -273,7 +283,13 @@ private void setNotification() { messageToShow = messageToShow.substring(0, 40); } - notification = new NotificationCompat.Builder(context).setSmallIcon(getNotificationIcon()).setLargeIcon(mBitmapIcon).setContentTitle(mHeader).setContentText(mContent).setCategory(NotificationCompat.CATEGORY_MESSAGE).setStyle(getBigStyle()).setContentIntent(pi).build(); + notification = new NotificationCompat.Builder(context, CHANNEL_ID) + .setSmallIcon(getNotificationIcon()) + .setLargeIcon(mBitmapIcon) + .setContentTitle(mHeader) + .setContentText(mContent).setCategory(NotificationCompat.CATEGORY_MESSAGE) + .setStyle(getBigStyle()) + .setContentIntent(pi).build(); if (currentAlarm + delayAlarm < System.currentTimeMillis()) { if (isMute) { @@ -323,9 +339,9 @@ private void alarmNotification(String messageToShow) { public void checkAlert(boolean updateNotification, ProtoGlobal.Room.Type type, long roomId) { - if (G.isAppInFg || AttachFile.isInAttach) { - return; - } +// if (G.isAppInFg || AttachFile.isInAttach) { +// return; +// } idRoom = roomId; int vipCheck = checkSpecialNotification(updateNotification, type, roomId); diff --git a/app/src/main/java/net/iGap/helper/HelperPublicMethod.java b/app/src/main/java/net/iGap/helper/HelperPublicMethod.java index 30c8894..46f1f5d 100644 --- a/app/src/main/java/net/iGap/helper/HelperPublicMethod.java +++ b/app/src/main/java/net/iGap/helper/HelperPublicMethod.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.helper; @@ -73,7 +73,16 @@ public void onChatGetRoomError(int majorCode, int minorCode) { } }; - new RequestChatGetRoom().chatGetRoom(peerId); + if (G.userLogin) { + new RequestChatGetRoom().chatGetRoom(peerId); + } else { + G.handler.postDelayed(new Runnable() { + @Override + public void run() { + goToChatRoom(peerId, onComplete, onError); + } + }, 1000); + } } realm.close(); } diff --git a/app/src/main/java/net/iGap/helper/HelperUploadFile.java b/app/src/main/java/net/iGap/helper/HelperUploadFile.java index a466f6f..63be870 100644 --- a/app/src/main/java/net/iGap/helper/HelperUploadFile.java +++ b/app/src/main/java/net/iGap/helper/HelperUploadFile.java @@ -162,7 +162,7 @@ public static boolean cancelUploading(String identity) { if (list.containsKey(identity)) { StructUpload _sp = list.remove(identity); - HelperDownloadFile.removeRequestQueue(identity); + HelperDownloadFile.getInstance().removeRequestQueue(identity); if (myQueue.contains(_sp)) { myQueue.remove(_sp); diff --git a/app/src/main/java/net/iGap/helper/HelperUrl.java b/app/src/main/java/net/iGap/helper/HelperUrl.java index 7098987..e1a90bc 100644 --- a/app/src/main/java/net/iGap/helper/HelperUrl.java +++ b/app/src/main/java/net/iGap/helper/HelperUrl.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.helper; @@ -39,6 +39,7 @@ import net.iGap.fragments.FragmentContactsProfile; import net.iGap.interfaces.OnAvatarGet; import net.iGap.interfaces.OnClientCheckInviteLink; +import net.iGap.interfaces.OnClientGetRoomMessage; import net.iGap.interfaces.OnClientJoinByInviteLink; import net.iGap.interfaces.OnClientResolveUsername; import net.iGap.module.AndroidUtils; @@ -49,7 +50,10 @@ import net.iGap.realm.RealmRegisteredInfo; import net.iGap.realm.RealmRoom; import net.iGap.realm.RealmRoomFields; +import net.iGap.realm.RealmRoomMessage; +import net.iGap.realm.RealmRoomMessageFields; import net.iGap.request.RequestClientCheckInviteLink; +import net.iGap.request.RequestClientGetRoomMessage; import net.iGap.request.RequestClientJoinByInviteLink; import net.iGap.request.RequestClientResolveUsername; @@ -181,11 +185,12 @@ public void onClick(View view) { @Override public void updateDrawState(TextPaint ds) { - if (G.isDarkTheme) { - ds.linkColor = LinkColorDark; - } else { - ds.linkColor = LinkColor; - } +// if (G.isDarkTheme) { +// ds.linkColor = LinkColorDark; +// } else { +// ds.linkColor = LinkColor; +// } + ds.linkColor = Color.parseColor(G.linkColor); super.updateDrawState(ds); ds.setUnderlineText(false); @@ -249,11 +254,14 @@ public void onClick(View view) { @Override public void updateDrawState(TextPaint ds) { - if (G.isDarkTheme) { - ds.linkColor = LinkColorDark; - } else { - ds.linkColor = LinkColor; - } +// if (G.isDarkTheme) { +// ds.linkColor = LinkColorDark; +// } else { +// ds.linkColor = LinkColor; +// } + + ds.linkColor = Color.parseColor(G.linkColor); + super.updateDrawState(ds); ds.setUnderlineText(false); } @@ -285,12 +293,12 @@ public void onClick(View view) { @Override public void updateDrawState(TextPaint ds) { - if (G.isDarkTheme) { - ds.linkColor = LinkColorDark; - } else { - ds.linkColor = LinkColor; - } - +// if (G.isDarkTheme) { +// ds.linkColor = LinkColorDark; +// } else { +// ds.linkColor = LinkColor; +// } + ds.linkColor = Color.parseColor(G.linkColor); super.updateDrawState(ds); ds.setUnderlineText(false); } @@ -358,11 +366,13 @@ public void onClick(View view) { @Override public void updateDrawState(TextPaint ds) { - if (G.isDarkTheme) { - ds.linkColor = LinkColorDark; - } else { - ds.linkColor = LinkColor; - } +// if (G.isDarkTheme) { +// ds.linkColor = LinkColorDark; +// } else { +// ds.linkColor = LinkColor; +// } + ds.linkColor = Color.parseColor(G.linkColor); + super.updateDrawState(ds); ds.setUnderlineText(false); } @@ -434,11 +444,13 @@ public void onClick(View view) { @Override public void updateDrawState(TextPaint ds) { - if (G.isDarkTheme) { - ds.linkColor = LinkColorDark; - } else { - ds.linkColor = LinkColor; - } +// if (G.isDarkTheme) { +// ds.linkColor = LinkColorDark; +// } else { +// ds.linkColor = LinkColor; +// } + ds.linkColor = Color.parseColor(G.linkColor); + super.updateDrawState(ds); ds.setUnderlineText(false); } @@ -752,15 +764,31 @@ private static boolean isInCurrentChat(String userName) { } public static void checkUsernameAndGoToRoom(final String userName, final ChatEntry chatEntery) { + checkUsernameAndGoToRoomWithMessageId(userName, chatEntery, 0); + } + - if (userName == null || userName.length() < 1 || isInCurrentChat(userName)) return; + /** + * @param username + * @param chatEntry + * @param messageId // use for detect message position + */ + + public static void checkUsernameAndGoToRoomWithMessageId(final String username, final ChatEntry chatEntry, final long messageId) { + + if (username == null || username.length() < 1 || isInCurrentChat(username)) return; if (G.userLogin) { + // this methode check user name and if it is ok go to room G.onClientResolveUsername = new OnClientResolveUsername() { @Override public void onClientResolveUsername(ProtoClientResolveUsername.ClientResolveUsernameResponse.Type type, ProtoGlobal.RegisteredUser user, ProtoGlobal.Room room) { - openChat(userName, type, user, room, chatEntery); + if (messageId == 0 || type == ProtoClientResolveUsername.ClientResolveUsernameResponse.Type.USER) { + openChat(username, type, user, room, chatEntry, messageId); + } else { + resolveMessageAndOpenChat(messageId, username, chatEntry, type, user, room); + } } @Override @@ -771,13 +799,42 @@ public void onError(int majorCode, int minorCode) { showIndeterminateProgressDialog(); - new RequestClientResolveUsername().clientResolveUsername(userName); + new RequestClientResolveUsername().clientResolveUsername(username); } else { closeDialogWaiting(); HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); } } + /** + * if message isn't exist in Realm resolve from server and then open chat + */ + private static void resolveMessageAndOpenChat(final long messageId, final String username, final ChatEntry chatEntry, final ProtoClientResolveUsername.ClientResolveUsernameResponse.Type type, final ProtoGlobal.RegisteredUser user, final ProtoGlobal.Room room) { + + Realm realm = Realm.getDefaultInstance(); + RealmRoomMessage rm = realm.where(RealmRoomMessage.class).equalTo(RealmRoomMessageFields.ROOM_ID, room.getId()).equalTo(RealmRoomMessageFields.MESSAGE_ID, messageId).findFirst(); + if (rm != null) { + openChat(username, type, user, room, chatEntry, messageId); + } else { + + RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, room.getId()).findFirst(); + if (realmRoom == null || realmRoom.isDeleted()) { + openChat(username, type, user, room, chatEntry, messageId); + } else { + new RequestClientGetRoomMessage().clientGetRoomMessage(room.getId(), messageId); + G.onClientGetRoomMessage = new OnClientGetRoomMessage() { + @Override + public void onClientGetRoomMessageResponse(final long messageId) { + RealmRoomMessage.setGap(messageId); + G.onClientGetRoomMessage = null; + openChat(username, type, user, room, chatEntry, messageId); + } + }; + } + } + realm.close(); + } + public static void closeDialogWaiting() { try { if (dialogWaiting != null && dialogWaiting.isShowing() && !(G.currentActivity).isFinishing()) { @@ -792,25 +849,25 @@ public static void closeDialogWaiting() { //************************************ go to room by userName ********************************************************************* - private static void openChat(String username, ProtoClientResolveUsername.ClientResolveUsernameResponse.Type type, ProtoGlobal.RegisteredUser user, ProtoGlobal.Room room, ChatEntry chatEntery) { + private static void openChat(String username, ProtoClientResolveUsername.ClientResolveUsernameResponse.Type type, ProtoGlobal.RegisteredUser user, ProtoGlobal.Room room, ChatEntry chatEntery, long messageId) { switch (type) { case USER: - goToChat(user, chatEntery); + goToChat(user, chatEntery, messageId); break; case ROOM: - goToRoom(username, room); + goToRoom(username, room, messageId); break; } } - private static void goToActivity(final long roomId, final long peerId, ChatEntry chatEntry) { + private static void goToActivity(final long roomId, final long peerId, ChatEntry chatEntry, final long messageId) { switch (chatEntry) { case chat: if (roomId != FragmentChat.lastChatRoomId) { - new GoToChatActivity(roomId).setPeerID(peerId).startActivity(); + new GoToChatActivity(roomId).setMessageID(messageId).setPeerID(peerId).startActivity(); } break; @@ -831,7 +888,7 @@ public void run() { } } - private static void goToChat(final ProtoGlobal.RegisteredUser user, final ChatEntry chatEntery) { + private static void goToChat(final ProtoGlobal.RegisteredUser user, final ChatEntry chatEntery, long messageId) { Long id = user.getId(); @@ -841,7 +898,7 @@ private static void goToChat(final ProtoGlobal.RegisteredUser user, final ChatEn if (realmRoom != null) { closeDialogWaiting(); - goToActivity(realmRoom.getId(), id, chatEntery); + goToActivity(realmRoom.getId(), id, chatEntery, messageId); realm.close(); } else { @@ -894,7 +951,7 @@ public void execute(Realm realm) { @Override public void onSuccess() { - goToActivity(roomId, user.getId(), chatEntery); + goToActivity(roomId, user.getId(), chatEntery, 0); realm.close(); } @@ -908,7 +965,7 @@ public void onError(Throwable error) { }); } - private static void goToRoom(String username, final ProtoGlobal.Room room) { + private static void goToRoom(String username, final ProtoGlobal.Room room, long messageId) { final Realm realm = Realm.getDefaultInstance(); @@ -922,7 +979,7 @@ private static void goToRoom(String username, final ProtoGlobal.Room room) { closeDialogWaiting(); if (room.getId() != FragmentChat.lastChatRoomId) { - new GoToChatActivity(room.getId()).startActivity(); + new GoToChatActivity(room.getId()).setMessageID(messageId).startActivity(); } } diff --git a/app/src/main/java/net/iGap/helper/contact/ContactsSyncAdapterService.java b/app/src/main/java/net/iGap/helper/contact/ContactsSyncAdapterService.java new file mode 100644 index 0000000..ca2731f --- /dev/null +++ b/app/src/main/java/net/iGap/helper/contact/ContactsSyncAdapterService.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright 2010 Sam Steele + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package net.iGap.helper.contact; + +import android.accounts.Account; +import android.accounts.OperationCanceledException; +import android.app.Service; +import android.content.AbstractThreadedSyncAdapter; +import android.content.ContentProviderClient; +import android.content.Context; +import android.content.Intent; +import android.content.SyncResult; +import android.os.Bundle; +import android.os.IBinder; +import android.util.Log; + +public class ContactsSyncAdapterService extends Service { + private static SyncAdapterImpl sSyncAdapter = null; + + public ContactsSyncAdapterService() { + super(); + } + + private static class SyncAdapterImpl extends AbstractThreadedSyncAdapter { + private Context mContext; + + public SyncAdapterImpl(Context context) { + super(context, true); + mContext = context; + } + + @Override + public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { + try { + ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult); + } catch (OperationCanceledException e) { + e.printStackTrace(); + } + } + } + + @Override + public IBinder onBind(Intent intent) { + return getSyncAdapter().getSyncAdapterBinder(); + } + + private SyncAdapterImpl getSyncAdapter() { + if (sSyncAdapter == null) { + sSyncAdapter = new SyncAdapterImpl(this); + } + return sSyncAdapter; + } + + private static void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException { + Log.i("Log", "performSync: " + account.toString()); + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/interfaces/IBackHandler.java b/app/src/main/java/net/iGap/interfaces/IBackHandler.java new file mode 100644 index 0000000..db47913 --- /dev/null +++ b/app/src/main/java/net/iGap/interfaces/IBackHandler.java @@ -0,0 +1,6 @@ +package net.iGap.interfaces; + +public interface IBackHandler { + + void onBack(); +} diff --git a/app/src/main/java/net/iGap/interfaces/OnInquiry.java b/app/src/main/java/net/iGap/interfaces/OnInquiry.java new file mode 100644 index 0000000..2e1bbb6 --- /dev/null +++ b/app/src/main/java/net/iGap/interfaces/OnInquiry.java @@ -0,0 +1,17 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.interfaces; + +public interface OnInquiry { + void OnInquiryResult(Object result); + + void OnInquiryError(); +} diff --git a/app/src/main/java/net/iGap/interfaces/OnMapViewChangeListener.java b/app/src/main/java/net/iGap/interfaces/OnMapViewChangeListener.java new file mode 100644 index 0000000..84b43c8 --- /dev/null +++ b/app/src/main/java/net/iGap/interfaces/OnMapViewChangeListener.java @@ -0,0 +1,6 @@ +package net.iGap.interfaces; + +public interface OnMapViewChangeListener { + public void onChangeTo(int state); + +} diff --git a/app/src/main/java/net/iGap/interfaces/OnMplResult.java b/app/src/main/java/net/iGap/interfaces/OnMplResult.java new file mode 100644 index 0000000..89fdce5 --- /dev/null +++ b/app/src/main/java/net/iGap/interfaces/OnMplResult.java @@ -0,0 +1,14 @@ +package net.iGap.interfaces; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +public interface OnMplResult { + void onResult(boolean error); +} diff --git a/app/src/main/java/net/iGap/interfaces/OnPathAdapterBottomSheet.java b/app/src/main/java/net/iGap/interfaces/OnPathAdapterBottomSheet.java index 86660e0..1822d51 100644 --- a/app/src/main/java/net/iGap/interfaces/OnPathAdapterBottomSheet.java +++ b/app/src/main/java/net/iGap/interfaces/OnPathAdapterBottomSheet.java @@ -10,7 +10,9 @@ package net.iGap.interfaces; +import net.iGap.module.structs.StructBottomSheet; + public interface OnPathAdapterBottomSheet { - void path(String path, boolean isCheck, boolean isEdit); + void path(String path, boolean isCheck, boolean isEdit, StructBottomSheet mList, int id); } diff --git a/app/src/main/java/net/iGap/interfaces/OnPayment.java b/app/src/main/java/net/iGap/interfaces/OnPayment.java new file mode 100644 index 0000000..773684e --- /dev/null +++ b/app/src/main/java/net/iGap/interfaces/OnPayment.java @@ -0,0 +1,19 @@ +package net.iGap.interfaces; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. +*/ + +public interface OnPayment { + void onChargeToken(int status, String token, int expireTime, String Message); + + void onBillToken(int status, String token, int expireTime, String Message); + + void onFinance(boolean mplActive, boolean walletActive); + +} diff --git a/app/src/main/java/net/iGap/interfaces/OnReceivePageInfoWalletAgreement.java b/app/src/main/java/net/iGap/interfaces/OnReceivePageInfoWalletAgreement.java new file mode 100644 index 0000000..43a9730 --- /dev/null +++ b/app/src/main/java/net/iGap/interfaces/OnReceivePageInfoWalletAgreement.java @@ -0,0 +1,15 @@ +/* +* This is the source code of iGap for Android +* It is licensed under GNU AGPL v3.0 +* You should have received a copy of the license in this archive (see LICENSE). +* Copyright © 2017 , iGap - www.iGap.net +* iGap Messenger | Free, Fast and Secure instant messaging application +* The idea of the RooyeKhat Media Company - www.RooyeKhat.co +* All rights reserved. +*/ + +package net.iGap.interfaces; + +public interface OnReceivePageInfoWalletAgreement { + void onReceivePageInfo(String body); +} diff --git a/app/src/main/java/net/iGap/libs/floatingAddButton/ArcMenu.java b/app/src/main/java/net/iGap/libs/floatingAddButton/ArcMenu.java index bb0cf2d..2a45f0c 100644 --- a/app/src/main/java/net/iGap/libs/floatingAddButton/ArcMenu.java +++ b/app/src/main/java/net/iGap/libs/floatingAddButton/ArcMenu.java @@ -67,7 +67,7 @@ public ArcMenu(Context context, AttributeSet attrs) { public void setBackgroundTintColor() { - fabMenu.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.appBarColor))); + fabMenu.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom))); } private void init(TypedArray attr) { diff --git a/app/src/main/java/net/iGap/libs/notification/GettingDeviceTokenService.java b/app/src/main/java/net/iGap/libs/notification/GettingDeviceTokenService.java new file mode 100644 index 0000000..da0a1f4 --- /dev/null +++ b/app/src/main/java/net/iGap/libs/notification/GettingDeviceTokenService.java @@ -0,0 +1,14 @@ +package net.iGap.libs.notification; + +import com.google.firebase.iid.FirebaseInstanceId; +import com.google.firebase.iid.FirebaseInstanceIdService; + +import net.iGap.realm.RealmUserInfo; + + +public class GettingDeviceTokenService extends FirebaseInstanceIdService { + @Override + public void onTokenRefresh() { + RealmUserInfo.setPushNotification(FirebaseInstanceId.getInstance().getToken()); + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/libs/notification/NotificationService.java b/app/src/main/java/net/iGap/libs/notification/NotificationService.java new file mode 100644 index 0000000..09debc9 --- /dev/null +++ b/app/src/main/java/net/iGap/libs/notification/NotificationService.java @@ -0,0 +1,74 @@ +package net.iGap.libs.notification; + +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.media.RingtoneManager; +import android.net.Uri; +import android.support.v4.app.NotificationCompat; + +import com.google.firebase.messaging.FirebaseMessagingService; +import com.google.firebase.messaging.RemoteMessage; + +import net.iGap.R; +import net.iGap.activities.ActivityMain; + + +public class NotificationService extends FirebaseMessagingService { + + private final static String ROOM_ID = "roomId"; + private final static String MESSAGE_ID = "messageId"; + private final static String MESSAGE_TYPE = "type"; + private final static String PAYLOAD = "payload"; + public static int NOTIFICATION_ID = 1000; + + @Override + public void onMessageReceived(RemoteMessage remoteMessage) { + +// if (remoteMessage.getData().size() > 0) { +// Map date = remoteMessage.getData(); +// if (date.containsKey(MESSAGE_TYPE)) { +// switch (date.get(MESSAGE_TYPE)){ +// case "ROOM_SEND_MESSAGE": +// if (date.containsKey(PAYLOAD)) { +// try { +// JSONObject payload = new JSONObject(date.get(PAYLOAD)); +// String roomId = payload.getString(ROOM_ID); +// String messageId = payload.getString(MESSAGE_ID); +// Log.e("ddd","romid : "+roomId+" messageId : "+messageId); +// } catch (JSONException e) { +// e.printStackTrace(); +// } +// generateNotification("ROOM_SEND_MESSAGE"); +// } +// break; +// case "SIGNALING_OFFER": +// Log.e("ddd"," push SIGNALING_OFFER "); +// break; +// } +// } +// } + } + + + private void generateNotification(String messageBody) { + + Intent intent = new Intent(this, ActivityMain.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); + Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); + NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(this) + .setSmallIcon(R.mipmap.icon) + .setContentTitle("IGap") + .setContentText(messageBody) + .setAutoCancel(true) + .setSound(defaultSoundUri) + .setContentIntent(pendingIntent); + NotificationManager notificationManager = + (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + notificationManager.notify(NOTIFICATION_ID, mNotifyBuilder.build()); + } + +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/module/AndroidUtils.java b/app/src/main/java/net/iGap/module/AndroidUtils.java index 2a319e0..5ea2cbd 100644 --- a/app/src/main/java/net/iGap/module/AndroidUtils.java +++ b/app/src/main/java/net/iGap/module/AndroidUtils.java @@ -25,6 +25,7 @@ import android.provider.MediaStore; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.util.TypedValue; import android.view.Display; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -586,4 +587,9 @@ public static void closeKeyboard(View v) { e.getStackTrace(); } } + + public static float dpToPx(Context context, float valueInDp) { + DisplayMetrics metrics = context.getResources().getDisplayMetrics(); + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, valueInDp, metrics); + } } \ No newline at end of file diff --git a/app/src/main/java/net/iGap/module/AppUtils.java b/app/src/main/java/net/iGap/module/AppUtils.java index f69c213..d02e830 100644 --- a/app/src/main/java/net/iGap/module/AppUtils.java +++ b/app/src/main/java/net/iGap/module/AppUtils.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.module; @@ -50,9 +50,11 @@ import net.iGap.realm.RealmRoomMessageFields; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import io.realm.Realm; import io.realm.RealmResults; @@ -204,6 +206,9 @@ public static String conversionMessageType(ProtoGlobal.RoomMessageType type, @Nu case LOCATION: result = G.fragmentActivity.getResources().getString(R.string.location_message); break; + case WALLET: + result = G.fragmentActivity.getResources().getString(R.string.wallet_message); + break; default: break; } @@ -218,8 +223,11 @@ public static String conversionMessageType(ProtoGlobal.RoomMessageType type, @Nu private static void getAndSetPositionPicture(final RealmRoomMessage message, final ImageView view) { - if (message.getLocation().getImagePath() != null) { - G.imageLoader.displayImage(AndroidUtils.suitablePath(message.getLocation().getImagePath()), view); + + String path = AppUtils.getLocationPath(message.getLocation().getLocationLat(), message.getLocation().getLocationLong()); + + if (new File(path).exists()) { + G.imageLoader.displayImage(AndroidUtils.suitablePath(AppUtils.getLocationPath(message.getLocation().getLocationLat(), message.getLocation().getLocationLong())), view); } else { FragmentMap.loadImageFromPosition(message.getLocation().getLocationLat(), message.getLocation().getLocationLong(), new FragmentMap.OnGetPicture() { @@ -227,8 +235,7 @@ private static void getAndSetPositionPicture(final RealmRoomMessage message, fin public void getBitmap(Bitmap bitmap) { view.setImageBitmap(bitmap); - - final String savedPath = FragmentMap.saveBitmapToFile(bitmap); + final String savedPath = AppUtils.saveMapToFile(bitmap, message.getLocation().getLocationLat(), message.getLocation().getLocationLong()); Realm realm = Realm.getDefaultInstance(); realm.executeTransaction(new Realm.Transaction() { @@ -245,6 +252,36 @@ public void execute(Realm realm) { } } + /** + * make location path with latitude & longitude in temp file + * + * @return location path in temp file + */ + public static String getLocationPath(double locationLat, double locationLong) { + return G.DIR_TEMP + "/location_" + String.valueOf(locationLat).replace(".", "") + "_" + String.valueOf(locationLong).replace(".", "") + ".png"; + } + + public static String saveMapToFile(Bitmap bitmap, Double latitude, Double longitude) { + + String result = ""; + + try { + if (bitmap == null) return result; + + String fileName = "/location_" + latitude.toString().replace(".", "") + "_" + longitude.toString().replace(".", "") + ".png"; + File file = new File(G.DIR_TEMP, fileName); + + OutputStream fOut = new FileOutputStream(file); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); + + result = file.getPath(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + return result; + } + /** * update message status automatically * @@ -269,7 +306,7 @@ public static void rightMessageStatus(ImageView view, ProtoGlobal.RoomMessageSta view.setColorFilter(Color.parseColor(G.tintImage), PorterDuff.Mode.SRC_IN); break; case FAILED: - setImageDrawable(view, R.drawable.ic_error); + setImageDrawable(view, R.drawable.ic_error_igap); view.setColorFilter(view.getContext().getResources().getColor(R.color.red)); break; case SEEN: @@ -313,7 +350,7 @@ public static void rightMessageStatus(ImageView view, ProtoGlobal.RoomMessageSta //DrawableCompat.setTint(view.getDrawable().mutate(), Color.BLACK); break; case FAILED: - setImageDrawable(view, R.drawable.ic_error); + setImageDrawable(view, R.drawable.ic_error_igap); if (messageType == ProtoGlobal.RoomMessageType.IMAGE || messageType == ProtoGlobal.RoomMessageType.VIDEO || messageType == ProtoGlobal.RoomMessageType.GIF) { DrawableCompat.setTint(view.getDrawable().mutate(), Color.WHITE); } else { @@ -384,7 +421,7 @@ public static String rightLastMessage(RealmRoomMessage message) { messageText = G.fragmentActivity.getString(R.string.last_msg_format_chat, attachment.getName()); break; case CONTACT: - messageText = "contact"; // need to fill messageText with a String because in return check null + messageText = "contact"; // need to fill messageText with a String because in return check null. this string isn't important. break; case FILE_TEXT: case FILE: @@ -426,6 +463,9 @@ public static String rightLastMessage(RealmRoomMessage message) { } messageText = G.fragmentActivity.getString(R.string.last_msg_format_chat, attachment.getName()); break; + case WALLET: + messageText = "wallet"; // need to fill messageText with a String because in return check null. this string isn't important. + break; default: messageText = null; break; @@ -657,7 +697,8 @@ public static void error(String error) { } public static long makeRandomId() { - return Math.abs(UUID.randomUUID().getLeastSignificantBits()); + return SUID.id().get(); + // return Math.abs(UUID.randomUUID().getLeastSignificantBits()); } } diff --git a/app/src/main/java/net/iGap/module/ContactUtils.java b/app/src/main/java/net/iGap/module/ContactUtils.java index d9cc019..c8664d9 100644 --- a/app/src/main/java/net/iGap/module/ContactUtils.java +++ b/app/src/main/java/net/iGap/module/ContactUtils.java @@ -1,15 +1,16 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.module; +import android.content.ContentProviderOperation; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; @@ -20,8 +21,23 @@ import android.provider.ContactsContract; import android.support.annotation.Nullable; +import com.afollestad.materialdialogs.MaterialDialog; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.helper.HelperPermission; +import net.iGap.interfaces.OnGetPermission; +import net.iGap.realm.RealmContacts; +import net.iGap.realm.RealmRegisteredInfo; + import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; + +import io.realm.Realm; +import io.realm.RealmResults; + +import static net.iGap.G.context; public final class ContactUtils { private Context mContext; @@ -112,4 +128,253 @@ public String retrieveName() { return contactName; } + + public static void addContactToPhoneBook(RealmRegisteredInfo contact) { + + String accountName = StartupActions.getiGapAccountInstance().name; + String accountType = StartupActions.getiGapAccountInstance().type; + + ContentResolver contentResolver = context.getContentResolver(); + try { + Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, accountName).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType).build(); + contentResolver.delete(rawContactUri, ContactsContract.RawContacts.SYNC2 + " = " + contact.getId(), null); + } catch (Exception e) { + e.printStackTrace(); + } + + ArrayList query = new ArrayList<>(); + + ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI); + builder.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, accountName); + builder.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType); + builder.withValue(ContactsContract.RawContacts.SYNC1, contact.getPhoneNumber()); + builder.withValue(ContactsContract.RawContacts.SYNC2, contact.getId()); + query.add(builder.build()); + + query.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) + .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) + .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, contact.getPhoneNumber()) + .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE) + .build()); + + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); + + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, contact.getFirstName()); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, contact.getLastName()); + query.add(builder.build()); + + /*final String IM_LABEL = "iGap protocol"; + ContentValues contentValues = new ContentValues(); + contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, 0); + contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE); + contentValues.put(ContactsContract.CommonDataKinds.Im.TYPE, ContactsContract.CommonDataKinds.Im.TYPE_CUSTOM); + contentValues.put(ContactsContract.CommonDataKinds.Im.LABEL, IM_LABEL); + contentValues.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM); + contentValues.put(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL, IM_LABEL); + contentValues.put(ContactsContract.CommonDataKinds.Im.DATA, currentAccount.name); + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValues(contentValues); + query.add(builder.build());*/ + + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.net.iGap.profile"); + builder.withValue(ContactsContract.Data.DATA1, contact.getId()); + builder.withValue(ContactsContract.Data.DATA2, "iGap Profile"); + builder.withValue(ContactsContract.Data.DATA3, "+" + contact.getPhoneNumber()); + builder.withValue(ContactsContract.Data.DATA4, contact.getId()); + query.add(builder.build()); + try { + G.context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, query); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void addContactToPhoneBook(RealmContacts contact) { + + String phoneNumber = contact.getPhone() + ""; + if (phoneNumber.startsWith("98")) { + phoneNumber = "+" + phoneNumber; + } else if (phoneNumber.startsWith("0")) { + phoneNumber = "+98" + phoneNumber.substring(1); + } + + String accountName = StartupActions.getiGapAccountInstance().name; + String accountType = StartupActions.getiGapAccountInstance().type; + + ContentResolver contentResolver = context.getContentResolver(); + try { + Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, accountName).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType).build(); + contentResolver.delete(rawContactUri, ContactsContract.RawContacts.SYNC2 + " = " + contact.getId(), null); + } catch (Exception e) { + e.printStackTrace(); + } + + + ArrayList query = new ArrayList<>(); + + ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI); + builder.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, accountName); + builder.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType); + builder.withValue(ContactsContract.RawContacts.SYNC1, phoneNumber); + builder.withValue(ContactsContract.RawContacts.SYNC2, contact.getId()); + + query.add(builder.build()); + + query.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) + .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) + .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneNumber) + .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE) + .build()); + + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + /* + * Sets the value of the raw contact id column to the new raw contact ID returned + * by the first operation in the batch. + */ + .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) + + // Sets the data row's MIME type to Phone + .withValue(ContactsContract.Data.MIMETYPE, + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) + .withValue(ContactsContract.Data.MIMETYPE, + ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE) + + + // Sets the phone number and type + .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneNumber) + .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE) + .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE) + .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_HOME); + + + // Builds the operation and adds it to the array of operations + query.add(builder.build()); + + + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); + + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, contact.getFirst_name()); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, contact.getLast_name()); + query.add(builder.build()); + + /*final String IM_LABEL = "iGap protocol"; + ContentValues contentValues = new ContentValues(); + contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, 0); + contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE); + contentValues.put(ContactsContract.CommonDataKinds.Im.TYPE, ContactsContract.CommonDataKinds.Im.TYPE_CUSTOM); + contentValues.put(ContactsContract.CommonDataKinds.Im.LABEL, IM_LABEL); + contentValues.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM); + contentValues.put(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL, IM_LABEL); + contentValues.put(ContactsContract.CommonDataKinds.Im.DATA, currentAccount.name); + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValues(contentValues); + query.add(builder.build());*/ + + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.net.iGap.profile"); + builder.withValue(ContactsContract.Data.DATA1, contact.getId()); + // builder.withValue(ContactsContract.Data.DATA2, "iGap Profile"); + builder.withValue(ContactsContract.Data.DATA2, "Call via my app"); + builder.withValue(ContactsContract.Data.DATA3, "Message " + phoneNumber); + builder.withValue(ContactsContract.Data.DATA4, contact.getId()); + + query.add(builder.build()); + + + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.net.iGap.call"); + builder.withValue(ContactsContract.Data.DATA1, contact.getId()); + // builder.withValue(ContactsContract.Data.DATA2, "iGap Profile"); + builder.withValue(ContactsContract.Data.DATA2, "Call via my app"); + builder.withValue(ContactsContract.Data.DATA3, "Voice call " + phoneNumber); + builder.withValue(ContactsContract.Data.DATA4, contact.getId()); + query.add(builder.build()); + + try { + G.context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, query); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * sync iGap contacts with phone contacts (add iGap Accounts to phone contacts that has iGap) + */ + public static void syncContacts() { + try { + HelperPermission.getContactPermision(G.fragmentActivity, new OnGetPermission() { + @Override + public void Allow() throws IOException { + final Realm realm = Realm.getDefaultInstance(); + realm.executeTransactionAsync(new Realm.Transaction() { + @Override + public void execute(final Realm realm) { + + final RealmResults realmContacts = realm.where(RealmContacts.class).findAll(); + final int contactsSize = realmContacts.size(); + final MaterialDialog[] dialog = new MaterialDialog[1]; + G.handler.post(new Runnable() { + @Override + public void run() { + dialog[0] = new MaterialDialog.Builder(G.currentActivity) + .title(R.string.sync_contact) + .content(R.string.just_wait_en) + .progress(false, contactsSize, true) + .show(); + } + }); + + for (RealmContacts realmContacts1 : realmContacts) { + addContactToPhoneBook(realmContacts1); + if (dialog[0].isCancelled()) { + break; + } + + G.handler.post(new Runnable() { + @Override + public void run() { + dialog[0].incrementProgress(1); + } + }); + } + + G.handler.postDelayed(new Runnable() { + @Override + public void run() { + dialog[0].dismiss(); + } + }, 500); + } + }, new Realm.Transaction.OnSuccess() { + @Override + public void onSuccess() { + realm.close(); + } + }, new Realm.Transaction.OnError() { + @Override + public void onError(Throwable error) { + realm.close(); + } + }); + } + + @Override + public void deny() { + // do nothing + } + }); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/app/src/main/java/net/iGap/module/FileUtils.java b/app/src/main/java/net/iGap/module/FileUtils.java index 5094315..91a1e60 100644 --- a/app/src/main/java/net/iGap/module/FileUtils.java +++ b/app/src/main/java/net/iGap/module/FileUtils.java @@ -29,6 +29,7 @@ import net.iGap.G; import net.iGap.R; import net.iGap.helper.HelperCalander; +import net.iGap.helper.HelperLog; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; @@ -314,6 +315,20 @@ public static String getPath(final Context context, final Uri uri) { if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; + } else { + String strPath; + if (Environment.isExternalStorageRemovable()) { + strPath = System.getenv("EXTERNAL_STORAGE"); + } else { + strPath = System.getenv("SECONDARY_STORAGE"); + if (strPath == null || strPath.length() == 0) { + strPath = System.getenv("EXTERNAL_SDCARD_STORAGE"); + } + } + if (strPath != null && strPath.length() > 0) { + return strPath + "/" + split[1]; + } + HelperLog.setErrorLog("FileUtils getPath : " + uri); } } diff --git a/app/src/main/java/net/iGap/module/LinedEditText.java b/app/src/main/java/net/iGap/module/LinedEditText.java index 0d48b13..2386840 100644 --- a/app/src/main/java/net/iGap/module/LinedEditText.java +++ b/app/src/main/java/net/iGap/module/LinedEditText.java @@ -13,13 +13,13 @@ import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.os.Build; import android.util.AttributeSet; import net.iGap.G; -import net.iGap.R; public class LinedEditText extends android.support.v7.widget.AppCompatEditText { @@ -60,7 +60,7 @@ private void init() { // instantiate the paint dashedLinePaint = new Paint(); - dashedLinePaint.setColor(G.context.getResources().getColor(R.color.line_edit_text)); + dashedLinePaint.setColor(Color.parseColor(G.lineBorder)); dashedLinePaint.setStyle(Paint.Style.STROKE); initialCount = 4; setLines(initialCount); @@ -101,9 +101,9 @@ protected void onFocusChanged(boolean focused, int direction, Rect previouslyFoc super.onFocusChanged(focused, direction, previouslyFocusedRect); if (focused) { - dashedLinePaint.setColor(G.context.getResources().getColor(R.color.toolbar_background)); + dashedLinePaint.setColor(Color.parseColor(G.appBarColor)); } else { - dashedLinePaint.setColor(G.context.getResources().getColor(R.color.line_edit_text)); + dashedLinePaint.setColor(Color.parseColor(G.lineBorder)); } } diff --git a/app/src/main/java/net/iGap/module/MusicPlayer.java b/app/src/main/java/net/iGap/module/MusicPlayer.java index f8ed5c2..d4135ca 100644 --- a/app/src/main/java/net/iGap/module/MusicPlayer.java +++ b/app/src/main/java/net/iGap/module/MusicPlayer.java @@ -50,6 +50,7 @@ import net.iGap.activities.ActivityMain; import net.iGap.fragments.FragmentChat; import net.iGap.fragments.FragmentMediaPlayer; +import net.iGap.fragments.FragmentShowImage; import net.iGap.helper.HelperCalander; import net.iGap.helper.HelperDownloadFile; import net.iGap.helper.HelperLog; @@ -311,8 +312,8 @@ public static void playAndPause() { } public static void pauseSound() { - - + if (FragmentShowImage.focusAudioListener != null) + FragmentShowImage.focusAudioListener.audioPlay(false); if (!isVoice) { try { remoteViews.setImageViewResource(R.id.mln_btn_play_music, R.mipmap.play_button); @@ -368,6 +369,9 @@ public static void playSound() { return; } + if (FragmentShowImage.focusAudioListener != null) + FragmentShowImage.focusAudioListener.audioPlay(true); + if (G.onAudioFocusChangeListener != null) { G.onAudioFocusChangeListener.onAudioFocusChangeListener(AudioManager.AUDIOFOCUS_GAIN); } @@ -474,6 +478,15 @@ public static void nextMusic() { String beforeMessageId = MusicPlayer.messageId; selectedMedia--; if (selectedMedia < 0) { + + if (isVoice) { // avoid from return to first voice + if (btnPlayMusic != null) { + btnPlayMusic.setText(context.getString(R.string.md_play_arrow)); + } + stopSound(); + return; + } + selectedMedia = mediaList.size() - 1; } RealmRoomMessage roomMessage = RealmRoomMessage.getFinalMessage(mediaList.get(selectedMedia)); @@ -539,13 +552,6 @@ public static void previousMusic() { selectedMedia++; if (selectedMedia >= mediaList.size()) { - if (isVoice) { // avoid from return to first voice - if (btnPlayMusic != null) { - btnPlayMusic.setText(context.getString(R.string.md_play_arrow)); - } - stopSound(); - return; - } selectedMedia = 0; } RealmRoomMessage roomMessage = null; @@ -1214,7 +1220,7 @@ private static boolean startDownload(RealmRoomMessage rm) { result = true; - HelperDownloadFile.startDownload(rm.getMessageId() + "", _token, _url, _cacheId, _name, _size, selector, _path, 0, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(rm.getMessageId() + "", _token, _url, _cacheId, _name, _size, selector, _path, 0, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(String path, int progress) { if (progress == 100) { diff --git a/app/src/main/java/net/iGap/module/SHP_SETTING.java b/app/src/main/java/net/iGap/module/SHP_SETTING.java index 8f2d81b..90af2fb 100644 --- a/app/src/main/java/net/iGap/module/SHP_SETTING.java +++ b/app/src/main/java/net/iGap/module/SHP_SETTING.java @@ -106,6 +106,10 @@ public class SHP_SETTING { public static final String KEY_KEEP_MEDIA_NEW = "KEY_KEEP_MEDIA_NEW"; // default color + + + public static final String KEY_THEME_COLOR = "KEY_THEME_COLOR"; + public static final String KEY_APP_BAR_COLOR = "KEY_APP_BAR_COLOR"; public static final String KEY_NOTIFICATION_COLOR = "KEY_NOTIFICATION_COLOR"; public static final String KEY_TOGGLE_BOTTON_COLOR = "KEY_TOGGLE_BOTTON_COLOR"; @@ -114,6 +118,15 @@ public class SHP_SETTING { public static final String KEY_MENU_BACKGROUND_COLOR = "KEY_MENU_BACKGROUND_COLOR"; public static final String KEY_PROGRES_COLOR = "KEY_PROGRES_COLOR"; + public static final String KEY_OLD_THEME_COLOR = "KEY_OLD_THEME_COLOR"; + public static final String KEY_APP_BAR_COLOR_DARK = "KEY_APP_BAR_COLOR_DARK"; + public static final String KEY_NOTIFICATION_COLOR_DARK = "KEY_NOTIFICATION_COLOR_DARK"; + public static final String KEY_TOGGLE_BOTTON_COLOR_DARK = "KEY_TOGGLE_BOTTON_COLOR_DARK"; + public static final String KEY_SEND_AND_ATTACH_ICON_COLOR_DARK = "KEY_SEND_AND_ATTACH_ICON_COLOR_DARK"; + public static final String KEY_FONT_HEADER_COLOR_DARK = "KEY_FONT_HEADER_COLOR_DARK"; + public static final String KEY_MENU_BACKGROUND_COLOR_DARK = "KEY_MENU_BACKGROUND_COLOR_DARK"; + public static final String KEY_PROGRES_COLOR_DARK = "KEY_PROGRES_COLOR_DARK"; + // ========================================================================================== chat background public static final String KEY_PATH_CHAT_BACKGROUND = "KEY_PATH_CHAT_BACKGROUND"; @@ -157,6 +170,9 @@ public class SHP_SETTING { public static final String KEY_SELECTED_MINUTE_TO = "KEY_SELECTED_MINUTE_TO"; public static final String KEY_SELECTED_MILISECOND_TO = "KEY_SELECTED_MILISECOND_TO"; + public static final String KEY_SWITCH_MAP_STATE = "KEY_SWITCH_MAP_STATE"; + + public static class Defaults { public static final int KEY_AUTOPLAY_GIFS = 1; } diff --git a/app/src/main/java/net/iGap/module/StartupActions.java b/app/src/main/java/net/iGap/module/StartupActions.java index 71f64c3..7c010e1 100644 --- a/app/src/main/java/net/iGap/module/StartupActions.java +++ b/app/src/main/java/net/iGap/module/StartupActions.java @@ -1,8 +1,11 @@ package net.iGap.module; +import android.accounts.Account; +import android.accounts.AccountManager; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.os.Build; import android.os.Environment; import android.util.DisplayMetrics; import android.view.WindowManager; @@ -12,17 +15,15 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; -import com.vanniktech.emoji.EmojiManager; -import com.vanniktech.emoji.one.EmojiOneProvider; import net.iGap.Config; import net.iGap.G; import net.iGap.R; +import net.iGap.Theme; import net.iGap.WebSocketClient; import net.iGap.adapter.items.chat.ViewMaker; import net.iGap.fragments.FragmentiGapMap; import net.iGap.helper.HelperCalander; -import net.iGap.helper.HelperDownloadFile; import net.iGap.helper.HelperFillLookUpClass; import net.iGap.helper.HelperNotificationAndBadge; import net.iGap.helper.HelperPermission; @@ -81,7 +82,7 @@ public final class StartupActions { public StartupActions() { detectDeviceType(); - EmojiManager.install(new EmojiOneProvider()); // This line needs to be executed before any usage of EmojiTextView or EmojiEditText. + // EmojiManager.install(new EmojiOneProvider()); // This line needs to be executed before any usage of EmojiTextView or EmojiEditText. initializeGlobalVariables(); realmConfiguration(); mainUserInfo(); @@ -91,13 +92,12 @@ public StartupActions() { ConnectionManager.manageConnection(); configDownloadManager(); manageTime(); - + getiGapAccountInstance(); new CallObserver(); /** * initialize download and upload listeners */ - new HelperDownloadFile(); new HelperUploadFile(); } @@ -192,7 +192,7 @@ private static void manageAppDirectories() { DIR_AUDIOS = rootPath + G.AUDIOS; DIR_DOCUMENT = rootPath + G.DOCUMENT; } else { - String selectedStorage = getSelectedStoragePath(); + String selectedStorage = getSelectedStoragePath(rootPath); DIR_IMAGES = selectedStorage + G.IMAGES; DIR_VIDEOS = selectedStorage + G.VIDEOS; DIR_AUDIOS = selectedStorage + G.AUDIOS; @@ -204,24 +204,48 @@ private static void manageAppDirectories() { DIR_IMAGE_USER = rootPath + G.IMAGE_USER; } - private static String getSelectedStoragePath() { - String selectedStorage = G.DIR_APP; + private static String getSelectedStoragePath(String cashPath) { + SharedPreferences sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); + boolean canWrite = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); + String selectedStorage = ""; + + if (canWrite) { + selectedStorage = G.DIR_APP; + } else { + selectedStorage = cashPath; + } if (sharedPreferences.getInt(SHP_SETTING.KEY_SDK_ENABLE, 0) == 1) { if (G.DIR_SDCARD_EXTERNAL.equals("")) { List storageList = FileUtils.getSdCardPathList(); if (storageList.size() > 0) { - G.DIR_SDCARD_EXTERNAL = storageList.get(0); - selectedStorage = G.DIR_SDCARD_EXTERNAL + IGAP; + String sdPath = ""; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + sdPath = storageList.get(0) + IGAP; + } else { + File exFile = G.context.getExternalFilesDir(null); + if (exFile != null) { + sdPath = storageList.get(0) + exFile.getAbsolutePath().substring(exFile.getAbsolutePath().indexOf("/Android")); + } + } + File sdFile = new File(sdPath); + if ((sdFile.exists() && sdFile.canWrite()) || sdFile.mkdirs()) { + G.DIR_SDCARD_EXTERNAL = selectedStorage = sdPath; + } else { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putInt(SHP_SETTING.KEY_SDK_ENABLE, 0); + editor.apply(); + } } else { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putInt(SHP_SETTING.KEY_SDK_ENABLE, 0); editor.apply(); } } else { - if (new File(G.DIR_SDCARD_EXTERNAL).exists()) { - selectedStorage = G.DIR_SDCARD_EXTERNAL + IGAP; + File sdFile = new File(G.DIR_SDCARD_EXTERNAL); + if ((sdFile.exists() && sdFile.canWrite()) || sdFile.mkdirs()) { + selectedStorage = G.DIR_SDCARD_EXTERNAL; } else { G.DIR_SDCARD_EXTERNAL = ""; } @@ -231,6 +255,36 @@ private static String getSelectedStoragePath() { return selectedStorage; } + /** + * if iGap Account not created yet, create otherwise just detect and return + */ + public static Account getiGapAccountInstance() { + + if (G.iGapAccount != null) { + return G.iGapAccount; + } + + AccountManager accountManager = AccountManager.get(G.context); + if (accountManager.getAccounts().length != 0) { + for (Account account : accountManager.getAccounts()) { + if (account.type.equals(G.context.getPackageName())) { + G.iGapAccount = account; + return G.iGapAccount; + } + } + } + + G.iGapAccount = new Account(Config.iGapAccount, G.context.getPackageName()); + String password = "net.iGap"; + try { + accountManager.addAccountExplicitly(G.iGapAccount, password, null); + } catch (Exception e1) { + e1.getMessage(); + } + + return G.iGapAccount; + } + public static File getCacheDir() { String state = null; try { @@ -306,27 +360,15 @@ private void manageSettingPreferences() { editor.apply(); } - G.isDarkTheme = preferences.getBoolean(SHP_SETTING.KEY_THEME_DARK, false); - - appBarColor = preferences.getString(SHP_SETTING.KEY_APP_BAR_COLOR, Config.default_appBarColor); - notificationColor = preferences.getString(SHP_SETTING.KEY_NOTIFICATION_COLOR, Config.default_notificationColor); - toggleButtonColor = preferences.getString(SHP_SETTING.KEY_TOGGLE_BOTTON_COLOR, Config.default_toggleButtonColor); - attachmentColor = preferences.getString(SHP_SETTING.KEY_SEND_AND_ATTACH_ICON_COLOR, Config.default_attachmentColor); - headerTextColor = preferences.getString(SHP_SETTING.KEY_FONT_HEADER_COLOR, Config.default_headerTextColor); - G.progressColor = preferences.getString(SHP_SETTING.KEY_PROGRES_COLOR, Config.default_progressColor); - +// G.isDarkTheme = preferences.getBoolean(SHP_SETTING.KEY_THEME_DARK, false); boolean isDisableAutoDarkTheme = preferences.getBoolean(SHP_SETTING.KEY_DISABLE_TIME_DARK_THEME, true); if (!isDisableAutoDarkTheme) { checkTimeForAutoTheme(preferences); } - if (G.isDarkTheme) { - Config.darkThemeColor(); + Theme.setThemeColor(); - } else { - Config.lightThemeColor(); - } G.multiTab = preferences.getBoolean(SHP_SETTING.KEY_MULTI_TAB, false); // setting for show layout vote in channel @@ -375,20 +417,20 @@ private void checkTimeForAutoTheme(SharedPreferences preferences) { //checkes whether the current time is between 14:49:00 and 20:11:13. G.isDarkTheme = true; - appBarColor = Config.default_dark_appBarColor; - notificationColor = Config.default_dark_notificationColor; - toggleButtonColor = Config.default_dark_toggleButtonColor; - attachmentColor = Config.default_dark_attachmentColor; - headerTextColor = Config.default_dark_headerTextColor; - G.progressColor = Config.default_dark_progressColor; + appBarColor = Theme.default_dark_appBarColor; + notificationColor = Theme.default_dark_notificationColor; + toggleButtonColor = Theme.default_dark_toggleButtonColor; + attachmentColor = Theme.default_dark_attachmentColor; + headerTextColor = Theme.default_dark_headerTextColor; + G.progressColor = Theme.default_dark_progressColor; } else { G.isDarkTheme = false; - appBarColor = Config.default_appBarColor; - notificationColor = Config.default_notificationColor; - toggleButtonColor = Config.default_toggleButtonColor; - attachmentColor = Config.default_attachmentColor; - headerTextColor = Config.default_headerTextColor; - G.progressColor = Config.default_progressColor; + appBarColor = Theme.default_appBarColor; + notificationColor = Theme.default_notificationColor; + toggleButtonColor = Theme.default_toggleButtonColor; + attachmentColor = Theme.default_attachmentColor; + headerTextColor = Theme.default_headerTextColor; + G.progressColor = Theme.default_progressColor; } } catch (ParseException e) { e.printStackTrace(); @@ -457,7 +499,7 @@ private void mainUserInfo() { RealmUserInfo userInfo = realm.where(RealmUserInfo.class).findFirst(); - if (userInfo != null) { + if (userInfo != null && userInfo.getUserRegistrationState()) { userId = userInfo.getUserId(); G.isPassCode = userInfo.isPassCode(); diff --git a/app/src/main/java/net/iGap/module/structs/StructBottomSheet.java b/app/src/main/java/net/iGap/module/structs/StructBottomSheet.java index d2f3e2a..6e1ab68 100644 --- a/app/src/main/java/net/iGap/module/structs/StructBottomSheet.java +++ b/app/src/main/java/net/iGap/module/structs/StructBottomSheet.java @@ -1,19 +1,32 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.module.structs; -public class StructBottomSheet { +import android.support.annotation.NonNull; +public class StructBottomSheet implements Comparable { + + public int id; public boolean isSelected; public String path; + private String text; + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } public boolean isSelected() { return isSelected; @@ -30,4 +43,17 @@ public String getPath() { public void setPath(String path) { this.path = path; } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + @Override + public int compareTo(@NonNull StructBottomSheet structBottomSheet) { + return structBottomSheet.id - id; + } } diff --git a/app/src/main/java/net/iGap/module/structs/StructMessageInfo.java b/app/src/main/java/net/iGap/module/structs/StructMessageInfo.java index ab03be2..35438e2 100644 --- a/app/src/main/java/net/iGap/module/structs/StructMessageInfo.java +++ b/app/src/main/java/net/iGap/module/structs/StructMessageInfo.java @@ -27,6 +27,7 @@ import io.realm.Realm; +import static net.iGap.G.themeColor; import static net.iGap.G.userId; /** @@ -76,6 +77,7 @@ public StructMessageInfo[] newArray(int size) { public byte[] fileHash; public int uploadProgress; public StructMessageAttachment attachment; + public StructWallet structWallet; public StructRegisteredInfo userInfo; public StructMessageAttachment senderAvatar; public long time; @@ -105,6 +107,7 @@ public StructMessageInfo(Realm realmChat, long roomId, String messageID, String if (this.attachment == null) { this.attachment = new StructMessageAttachment(); } + this.attachment.setLocalThumbnailPath(Long.parseLong(messageID), localThumbnailPath); this.attachment.setLocalFilePath(Long.parseLong(messageID), localFilePath); this.fileHash = fileHash; @@ -344,6 +347,10 @@ public static StructMessageInfo convert(Realm realmChat, RealmRoomMessage roomMe messageInfo.logs = roomMessage.getLogs(); } + if (roomMessage.getRoomMessageWallet() != null) { + messageInfo.structWallet = StructWallet.convert(roomMessage.getRoomMessageWallet()); + } + messageInfo.replayTo = roomMessage.getReplyTo(); RealmChannelExtra realmChannelExtra = realmChat.where(RealmChannelExtra.class).equalTo(RealmChannelExtraFields.MESSAGE_ID, roomMessage.getMessageId()).findFirst(); if (realmChannelExtra != null) { diff --git a/app/src/main/java/net/iGap/module/structs/StructWallet.java b/app/src/main/java/net/iGap/module/structs/StructWallet.java new file mode 100644 index 0000000..dfcc1dc --- /dev/null +++ b/app/src/main/java/net/iGap/module/structs/StructWallet.java @@ -0,0 +1,49 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.module.structs; + +import net.iGap.G; +import net.iGap.realm.RealmChannelExtra; +import net.iGap.realm.RealmRoom; +import net.iGap.realm.RealmRoomMessageWallet; + +import org.parceler.Parcel; + +import io.realm.annotations.PrimaryKey; + +@Parcel +public class StructWallet { + + public long id; + public String type; + public long fromUserId; + public long toUserId; + public long amount; + public long traceNumber; + public long invoiceNumber; + public int payTime; + public String description; + + public static StructWallet convert(RealmRoomMessageWallet realmRoomMessageWallet) { + + StructWallet structWallet = new StructWallet(); + structWallet.id = realmRoomMessageWallet.getId(); + structWallet.fromUserId = realmRoomMessageWallet.getFromUserId(); + structWallet.toUserId = realmRoomMessageWallet.getToUserId(); + structWallet.amount = realmRoomMessageWallet.getAmount(); + structWallet.traceNumber = realmRoomMessageWallet.getTraceNumber(); + structWallet.invoiceNumber = realmRoomMessageWallet.getInvoiceNumber(); + structWallet.payTime = realmRoomMessageWallet.getPayTime(); + structWallet.description = realmRoomMessageWallet.getDescription(); + return structWallet; + } + +} diff --git a/app/src/main/java/net/iGap/realm/RealmContacts.java b/app/src/main/java/net/iGap/realm/RealmContacts.java index 04ef33a..672aceb 100644 --- a/app/src/main/java/net/iGap/realm/RealmContacts.java +++ b/app/src/main/java/net/iGap/realm/RealmContacts.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.realm; diff --git a/app/src/main/java/net/iGap/realm/RealmMigration.java b/app/src/main/java/net/iGap/realm/RealmMigration.java index fd2d1d6..6f1dd88 100644 --- a/app/src/main/java/net/iGap/realm/RealmMigration.java +++ b/app/src/main/java/net/iGap/realm/RealmMigration.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.realm; @@ -210,7 +210,7 @@ public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { oldVersion++; } - if (oldVersion == REALM_LATEST_MIGRATION_VERSION) { // REALM_LATEST_MIGRATION_VERSION = 17 + if (oldVersion == 17) { RealmObjectSchema realmRoom = schema.get(RealmRoom.class.getSimpleName()); if (realmRoom != null) { realmRoom.addField(RealmRoomFields.PIN_MESSAGE_ID, long.class, FieldAttribute.REQUIRED); @@ -248,5 +248,36 @@ public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { oldVersion++; } + + if (oldVersion == 18) { + RealmObjectSchema realmUserInfo = schema.get(RealmUserInfo.class.getSimpleName()); + if (realmUserInfo != null) { + realmUserInfo.addField(RealmUserInfoFields.PUSH_NOTIFICATION_TOKEN, String.class); + } + + oldVersion++; + } + + if (oldVersion == REALM_LATEST_MIGRATION_VERSION) { // REALM_LATEST_MIGRATION_VERSION = 19 + + RealmObjectSchema realmRoomMessageWallet = schema.create(RealmRoomMessageWallet.class.getSimpleName()) + .addField(RealmRoomMessageWalletFields.ID, long.class, FieldAttribute.REQUIRED) + .addPrimaryKey(RealmRoomMessageWalletFields.ID) + .addField(RealmRoomMessageWalletFields.FROM_USER_ID, long.class, FieldAttribute.REQUIRED) + .addField(RealmRoomMessageWalletFields.TO_USER_ID, long.class, FieldAttribute.REQUIRED) + .addField(RealmRoomMessageWalletFields.AMOUNT, long.class, FieldAttribute.REQUIRED) + .addField(RealmRoomMessageWalletFields.TRACE_NUMBER, long.class, FieldAttribute.REQUIRED) + .addField(RealmRoomMessageWalletFields.INVOICE_NUMBER, long.class, FieldAttribute.REQUIRED) + .addField(RealmRoomMessageWalletFields.PAY_TIME, int.class, FieldAttribute.REQUIRED) + .addField(RealmRoomMessageWalletFields.TYPE, String.class) + .addField(RealmRoomMessageWalletFields.DESCRIPTION, String.class); + + RealmObjectSchema realmRoomMessage = schema.get(RealmRoomMessage.class.getSimpleName()); + if (realmRoomMessage != null) { + realmRoomMessage.addRealmObjectField("roomMessageWallet", realmRoomMessageWallet); + } + + oldVersion++; + } } } diff --git a/app/src/main/java/net/iGap/realm/RealmPhoneContacts.java b/app/src/main/java/net/iGap/realm/RealmPhoneContacts.java index cfa07a6..bbf93f8 100644 --- a/app/src/main/java/net/iGap/realm/RealmPhoneContacts.java +++ b/app/src/main/java/net/iGap/realm/RealmPhoneContacts.java @@ -11,6 +11,7 @@ package net.iGap.realm; import net.iGap.G; +import net.iGap.helper.HelperLog; import net.iGap.helper.HelperString; import net.iGap.interfaces.OnQueueSendContact; import net.iGap.module.Contacts; @@ -163,9 +164,14 @@ public void execute(Realm realm) { continue; } - if (realm.where(RealmPhoneContacts.class).equalTo(RealmPhoneContactsFields.PHONE, checkString(_item)).findFirst() == null) { - notImportedList.add(_item); + try { + if (realm.where(RealmPhoneContacts.class).equalTo(RealmPhoneContactsFields.PHONE, checkString(_item)).findFirst() == null) { + notImportedList.add(_item); + } + } catch (IllegalArgumentException e) { + HelperLog.setErrorLog("RealmPhoneContacts addContactToDB phone : " + _item.getPhone() + " firstName : " + _item.getFirstName() + " lastname : " + _item.getLastName()); } + } } }); diff --git a/app/src/main/java/net/iGap/realm/RealmRoom.java b/app/src/main/java/net/iGap/realm/RealmRoom.java index 6a4e0ed..f0eb77d 100644 --- a/app/src/main/java/net/iGap/realm/RealmRoom.java +++ b/app/src/main/java/net/iGap/realm/RealmRoom.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.realm; diff --git a/app/src/main/java/net/iGap/realm/RealmRoomMessage.java b/app/src/main/java/net/iGap/realm/RealmRoomMessage.java index 364aed6..3da308b 100644 --- a/app/src/main/java/net/iGap/realm/RealmRoomMessage.java +++ b/app/src/main/java/net/iGap/realm/RealmRoomMessage.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.realm; @@ -80,6 +80,7 @@ public class RealmRoomMessage extends RealmObject { private long userId; private RealmRoomMessageLocation location; private RealmRoomMessageContact roomMessageContact; + private RealmRoomMessageWallet roomMessageWallet; private boolean edited; private long createTime; private long updateTime; @@ -420,6 +421,12 @@ public static RealmRoomMessage putOrUpdate(ProtoGlobal.RoomMessage input, long r if (input.hasContact()) { message.setRoomMessageContact(RealmRoomMessageContact.put(input.getContact())); } + + if (input.hasWallet()) { + //wallet put + message.setRoomMessageWallet(RealmRoomMessageWallet.put(input.getWallet())); + } + message.setMessageType(input.getMessageType()); message.setMessageVersion(input.getMessageVersion()); message.setStatusVersion(input.getStatusVersion()); @@ -728,7 +735,7 @@ public void execute(Realm realm) { // stop download if (roomMessage.getAttachment() != null) { - HelperDownloadFile.stopDownLoad(roomMessage.getAttachment().getCacheId()); + HelperDownloadFile.getInstance().stopDownLoad(roomMessage.getAttachment().getCacheId()); } } @@ -901,7 +908,25 @@ public static RealmRoomMessage setStatusServerResponse(Realm realm, long message return roomMessage; } - + /** + * set new gap state for UP and DOWN for {@param messageId} (BothDirections) + * + * @param messageId message that want set gapMessageId to that + */ + public static void setGap(final long messageId) { + Realm realm = Realm.getDefaultInstance(); + realm.executeTransaction(new Realm.Transaction() { + @Override + public void execute(Realm realm) { + RealmRoomMessage realmRoomMessage = realm.where(RealmRoomMessage.class).equalTo(RealmRoomMessageFields.MESSAGE_ID, messageId).findFirst(); + if (realmRoomMessage != null) { + realmRoomMessage.setPreviousMessageId(messageId); + realmRoomMessage.setFutureMessageId(messageId); + } + } + }); + realm.close(); + } /*public int getVoteUp() { return voteUp; @@ -1211,6 +1236,14 @@ public void setRoomMessageContact(RealmRoomMessageContact roomMessageContact) { this.roomMessageContact = roomMessageContact; } + public RealmRoomMessageWallet getRoomMessageWallet() { + return roomMessageWallet; + } + + private void setRoomMessageWallet(RealmRoomMessageWallet roomMessageWallet) { + this.roomMessageWallet = roomMessageWallet; + } + public boolean isEdited() { return edited; } diff --git a/app/src/main/java/net/iGap/realm/RealmRoomMessageLocation.java b/app/src/main/java/net/iGap/realm/RealmRoomMessageLocation.java index 6669f32..133ad58 100644 --- a/app/src/main/java/net/iGap/realm/RealmRoomMessageLocation.java +++ b/app/src/main/java/net/iGap/realm/RealmRoomMessageLocation.java @@ -22,11 +22,12 @@ @Parcel(implementations = {net_iGap_realm_RealmRoomMessageLocationRealmProxy.class}, value = Parcel.Serialization.BEAN, analyze = {RealmRoomMessageLocation.class}) public class RealmRoomMessageLocation extends RealmObject { - private double locationLat; - private double locationLong; - private String imagePath; + @PrimaryKey private long id; + private double locationLat; + private double locationLong; + private String imagePath; // this field not important now, because we use from 'locationLat' and 'locationLat' params for detect location path public static RealmRoomMessageLocation put(final ProtoGlobal.RoomMessageLocation input, Long id) { Realm realm = Realm.getDefaultInstance(); diff --git a/app/src/main/java/net/iGap/realm/RealmRoomMessageWallet.java b/app/src/main/java/net/iGap/realm/RealmRoomMessageWallet.java new file mode 100644 index 0000000..485903a --- /dev/null +++ b/app/src/main/java/net/iGap/realm/RealmRoomMessageWallet.java @@ -0,0 +1,124 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.realm; + +import net.iGap.module.AppUtils; +import net.iGap.proto.ProtoGlobal; + +import io.realm.Realm; +import io.realm.RealmObject; +import io.realm.annotations.PrimaryKey; + +public class RealmRoomMessageWallet extends RealmObject { + + @PrimaryKey + private long id; + private String type; + private long fromUserId; + private long toUserId; + private long amount; + private long traceNumber; + private long invoiceNumber; + private int payTime; + private String description; + + public static RealmRoomMessageWallet put(final ProtoGlobal.RoomMessageWallet input) { + Realm realm = Realm.getDefaultInstance(); + RealmRoomMessageWallet messageWallet = null; + messageWallet = realm.createObject(RealmRoomMessageWallet.class, AppUtils.makeRandomId()); + + messageWallet.setType(input.getType().toString()); + messageWallet.setFromUserId(input.getMoneyTransfer().getFromUserId()); + messageWallet.setToUserId(input.getMoneyTransfer().getToUserId()); + messageWallet.setAmount(input.getMoneyTransfer().getAmount()); + messageWallet.setTraceNumber(input.getMoneyTransfer().getTraceNumber()); + messageWallet.setInvoiceNumber(input.getMoneyTransfer().getInvoiceNumber()); + messageWallet.setPayTime(input.getMoneyTransfer().getPayTime()); + messageWallet.setDescription(input.getMoneyTransfer().getDescription()); + + realm.close(); + + return messageWallet; + } + + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public long getFromUserId() { + return fromUserId; + } + + public void setFromUserId(long fromUserId) { + this.fromUserId = fromUserId; + } + + public long getToUserId() { + return toUserId; + } + + public void setToUserId(long toUserId) { + this.toUserId = toUserId; + } + + public long getAmount() { + return amount; + } + + public void setAmount(long amount) { + this.amount = amount; + } + + public long getTraceNumber() { + return traceNumber; + } + + public void setTraceNumber(long traceNumber) { + this.traceNumber = traceNumber; + } + + public long getInvoiceNumber() { + return invoiceNumber; + } + + public void setInvoiceNumber(long invoiceNumber) { + this.invoiceNumber = invoiceNumber; + } + + public int getPayTime() { + return payTime; + } + + public void setPayTime(int payTime) { + this.payTime = payTime; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/app/src/main/java/net/iGap/realm/RealmUserInfo.java b/app/src/main/java/net/iGap/realm/RealmUserInfo.java index 38e5015..7172d03 100644 --- a/app/src/main/java/net/iGap/realm/RealmUserInfo.java +++ b/app/src/main/java/net/iGap/realm/RealmUserInfo.java @@ -12,6 +12,7 @@ import net.iGap.helper.HelperString; import net.iGap.proto.ProtoGlobal; +import net.iGap.request.RequestClientRegisterDevice; import io.realm.Realm; import io.realm.RealmObject; @@ -30,6 +31,7 @@ public class RealmUserInfo extends RealmObject { private String token; private String authorHash; private boolean importContactLimit; + private String pushNotificationToken; public static RealmUserInfo getRealmUserInfo(Realm realm) { return realm.where(RealmUserInfo.class).findFirst(); @@ -39,6 +41,8 @@ public static RealmUserInfo putOrUpdate(Realm realm, long userId, String usernam RealmUserInfo userInfo = realm.where(RealmUserInfo.class).findFirst(); if (userInfo == null) { userInfo = realm.createObject(RealmUserInfo.class); + } + if (userInfo.getUserInfo() == null) { RealmRegisteredInfo registeredInfo = RealmRegisteredInfo.getRegistrationInfo(realm, userId); if (registeredInfo == null) { registeredInfo = realm.createObject(RealmRegisteredInfo.class, userId); @@ -65,6 +69,33 @@ public static RealmUserInfo putOrUpdate(Realm realm, ProtoGlobal.RegisteredUser return realmUserInfo; } + public static void setPushNotification(final String pushToken) { + Realm realm = Realm.getDefaultInstance(); + realm.executeTransaction(new Realm.Transaction() { + @Override + public void execute(Realm realm) { + RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst(); + if (realmUserInfo != null) { + realmUserInfo.setPushNotificationToken(pushToken); + } else { + realmUserInfo = realm.createObject(RealmUserInfo.class); + realmUserInfo.setPushNotificationToken(pushToken); + } + } + }); + } + + public static void sendPushNotificationToServer() { + Realm realm = Realm.getDefaultInstance(); + RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst(); + if (realmUserInfo != null) { + String token = realmUserInfo.getPushNotificationToken(); + if (token != null && token.length() > 0) { + new RequestClientRegisterDevice().clientRegisterDevice(token); + } + } + } + public static void updateGender(final ProtoGlobal.Gender gender) { Realm realm = Realm.getDefaultInstance(); realm.executeTransaction(new Realm.Transaction() { @@ -283,4 +314,12 @@ public void setImportContactLimit(boolean value) { importContactLimit = value; } + public String getPushNotificationToken() { + return pushNotificationToken; + } + + public void setPushNotificationToken(String pushNotificationToken) { + this.pushNotificationToken = pushNotificationToken; + } + } diff --git a/app/src/main/java/net/iGap/request/RequestBillInquiryMci.java b/app/src/main/java/net/iGap/request/RequestBillInquiryMci.java new file mode 100644 index 0000000..eff470a --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestBillInquiryMci.java @@ -0,0 +1,27 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.request; + +import net.iGap.proto.ProtoBillInquiryMci; + +public class RequestBillInquiryMci { + + public void billInquiryMci(long mobileNumber) { + ProtoBillInquiryMci.BillInquiryMci.Builder builder = ProtoBillInquiryMci.BillInquiryMci.newBuilder(); + builder.setMobileNumber(mobileNumber); + RequestWrapper requestWrapper = new RequestWrapper(9200, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/request/RequestBillInquiryTelecom.java b/app/src/main/java/net/iGap/request/RequestBillInquiryTelecom.java new file mode 100644 index 0000000..9a89832 --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestBillInquiryTelecom.java @@ -0,0 +1,29 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.request; + +import net.iGap.proto.ProtoBillInquiryTelecom; + +public class RequestBillInquiryTelecom { + + public void billInquiryTelecom(int provinceCode, long phoneNumber) { + ProtoBillInquiryTelecom.BillInquiryTelecom.Builder builder = ProtoBillInquiryTelecom.BillInquiryTelecom.newBuilder(); + builder.setProvinceCode(provinceCode); + builder.setTelephoneNumber(phoneNumber); + + RequestWrapper requestWrapper = new RequestWrapper(9201, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/request/RequestClientRegisterDevice.java b/app/src/main/java/net/iGap/request/RequestClientRegisterDevice.java new file mode 100644 index 0000000..50b838b --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestClientRegisterDevice.java @@ -0,0 +1,28 @@ +/* +* This is the source code of iGap for Android +* It is licensed under GNU AGPL v3.0 +* You should have received a copy of the license in this archive (see LICENSE). +* Copyright © 2017 , iGap - www.iGap.net +* iGap Messenger | Free, Fast and Secure instant messaging application +* The idea of the RooyeKhat Media Company - www.RooyeKhat.co +* All rights reserved. +*/ + +package net.iGap.request; + +import net.iGap.proto.ProtoClientRegisterDevice; + +public class RequestClientRegisterDevice { + + public void clientRegisterDevice(String token) { + ProtoClientRegisterDevice.ClientRegisterDevice.Builder builder = ProtoClientRegisterDevice.ClientRegisterDevice.newBuilder(); + builder.setToken(token); + + RequestWrapper requestWrapper = new RequestWrapper(617, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/net/iGap/request/RequestInfoPage.java b/app/src/main/java/net/iGap/request/RequestInfoPage.java index 956f5c5..3ea8ec8 100644 --- a/app/src/main/java/net/iGap/request/RequestInfoPage.java +++ b/app/src/main/java/net/iGap/request/RequestInfoPage.java @@ -21,7 +21,7 @@ public void infoPage(String id) { infoPage.setRequest(ProtoRequest.Request.newBuilder().setId(HelperString.generateKey())); infoPage.setId(id); - RequestWrapper requestWrapper = new RequestWrapper(503, infoPage); + RequestWrapper requestWrapper = new RequestWrapper(503, infoPage, id); try { RequestQueue.sendRequest(requestWrapper); } catch (IllegalAccessException e) { diff --git a/app/src/main/java/net/iGap/request/RequestMplGetBillToken.java b/app/src/main/java/net/iGap/request/RequestMplGetBillToken.java new file mode 100644 index 0000000..193bf18 --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestMplGetBillToken.java @@ -0,0 +1,29 @@ +/* +* This is the source code of iGap for Android +* It is licensed under GNU AGPL v3.0 +* You should have received a copy of the license in this archive (see LICENSE). +* Copyright © 2017 , iGap - www.iGap.net +* iGap Messenger | Free, Fast and Secure instant messaging application +* The idea of the RooyeKhat Media Company - www.RooyeKhat.co +* All rights reserved. +*/ + +package net.iGap.request; + +import net.iGap.proto.ProtoMplGetBillToken; + +public class RequestMplGetBillToken { + + public void mplGetBillToken(long billId, long payId) { + ProtoMplGetBillToken.MplGetBillToken.Builder builder = ProtoMplGetBillToken.MplGetBillToken.newBuilder(); + builder.setBillId(billId); + builder.setPayId(payId); + + RequestWrapper requestWrapper = new RequestWrapper(9100, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/net/iGap/request/RequestMplGetTopupToken.java b/app/src/main/java/net/iGap/request/RequestMplGetTopupToken.java new file mode 100644 index 0000000..0012497 --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestMplGetTopupToken.java @@ -0,0 +1,30 @@ +/* +* This is the source code of iGap for Android +* It is licensed under GNU AGPL v3.0 +* You should have received a copy of the license in this archive (see LICENSE). +* Copyright © 2017 , iGap - www.iGap.net +* iGap Messenger | Free, Fast and Secure instant messaging application +* The idea of the RooyeKhat Media Company - www.RooyeKhat.co +* All rights reserved. +*/ + +package net.iGap.request; + +import net.iGap.proto.ProtoMplGetTopupToken; + +public class RequestMplGetTopupToken { + + public void mplGetTopupToken(long chargeMobileNumber, long amount, ProtoMplGetTopupToken.MplGetTopupToken.Type type) { + ProtoMplGetTopupToken.MplGetTopupToken.Builder builder = ProtoMplGetTopupToken.MplGetTopupToken.newBuilder(); + builder.setChargeMobileNumber(chargeMobileNumber); + builder.setAmount(amount); + builder.setType(type); + + RequestWrapper requestWrapper = new RequestWrapper(9101, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/net/iGap/request/RequestWalletGetAccessToken.java b/app/src/main/java/net/iGap/request/RequestWalletGetAccessToken.java new file mode 100644 index 0000000..01547a6 --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestWalletGetAccessToken.java @@ -0,0 +1,28 @@ +/* +* This is the source code of iGap for Android +* It is licensed under GNU AGPL v3.0 +* You should have received a copy of the license in this archive (see LICENSE). +* Copyright © 2017 , iGap - www.iGap.net +* iGap Messenger | Free, Fast and Secure instant messaging application +* The idea of the RooyeKhat Media Company - www.RooyeKhat.co +* All rights reserved. +*/ + +package net.iGap.request; + +import net.iGap.proto.ProtoWalletGetAccessToken; + +public class RequestWalletGetAccessToken { + + public void walletGetAccessToken() { + + ProtoWalletGetAccessToken.WalletGetAccessToken.Builder builder = ProtoWalletGetAccessToken.WalletGetAccessToken.newBuilder(); + + RequestWrapper requestWrapper = new RequestWrapper(9000, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/net/iGap/request/RequestWalletIdMapping.java b/app/src/main/java/net/iGap/request/RequestWalletIdMapping.java new file mode 100644 index 0000000..b3f59f0 --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestWalletIdMapping.java @@ -0,0 +1,28 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.request; + +import net.iGap.proto.ProtoWalletIdMapping; + +public class RequestWalletIdMapping { + + public void walletIdMapping(String walletId) { + ProtoWalletIdMapping.WalletIdMapping.Builder builder = ProtoWalletIdMapping.WalletIdMapping.newBuilder(); + builder.setWalletId(walletId); + + RequestWrapper requestWrapper = new RequestWrapper(9003, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/net/iGap/request/RequestWalletPaymentInit.java b/app/src/main/java/net/iGap/request/RequestWalletPaymentInit.java new file mode 100644 index 0000000..5f46b12 --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestWalletPaymentInit.java @@ -0,0 +1,33 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.request; + +import net.iGap.proto.ProtoGlobal; +import net.iGap.proto.ProtoWalletPaymentInit; + +public class RequestWalletPaymentInit { + + public void walletPaymentInit(ProtoGlobal.Language language, String jwt, long toUserId, long amount, String description) { + ProtoWalletPaymentInit.WalletPaymentInit.Builder builder = ProtoWalletPaymentInit.WalletPaymentInit.newBuilder(); + builder.setLanguage(language); + builder.setJwt(jwt); + builder.setToUserId(toUserId); + builder.setAmount(amount); + builder.setDescription(description); + + RequestWrapper requestWrapper = new RequestWrapper(9001, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/net/iGap/request/RequestWalletRegister.java b/app/src/main/java/net/iGap/request/RequestWalletRegister.java new file mode 100644 index 0000000..5a0a67c --- /dev/null +++ b/app/src/main/java/net/iGap/request/RequestWalletRegister.java @@ -0,0 +1,26 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.request; + +import net.iGap.proto.ProtoWalletRegister; + +public class RequestWalletRegister { + + public void walletRegister() { + ProtoWalletRegister.WalletRegister.Builder builder = ProtoWalletRegister.WalletRegister.newBuilder(); + RequestWrapper requestWrapper = new RequestWrapper(9002, builder); + try { + RequestQueue.sendRequest(requestWrapper); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/net/iGap/response/BillInquiryMciResponse.java b/app/src/main/java/net/iGap/response/BillInquiryMciResponse.java new file mode 100644 index 0000000..4054447 --- /dev/null +++ b/app/src/main/java/net/iGap/response/BillInquiryMciResponse.java @@ -0,0 +1,52 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.response; + +import net.iGap.G; + +public class BillInquiryMciResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + + public BillInquiryMciResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + + if (G.onInquiry != null) { + G.onInquiry.OnInquiryResult(message); + } + + } + + @Override + public void timeOut() { + super.timeOut(); + } + + @Override + public void error() { + super.error(); + + if (G.onInquiry != null) { + G.onInquiry.OnInquiryError(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/response/BillInquiryTelecomResponse.java b/app/src/main/java/net/iGap/response/BillInquiryTelecomResponse.java new file mode 100644 index 0000000..00ab630 --- /dev/null +++ b/app/src/main/java/net/iGap/response/BillInquiryTelecomResponse.java @@ -0,0 +1,52 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.response; + +import net.iGap.G; + +public class BillInquiryTelecomResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + + public BillInquiryTelecomResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + + if (G.onInquiry != null) { + G.onInquiry.OnInquiryResult(message); + } + + } + + @Override + public void timeOut() { + super.timeOut(); + } + + @Override + public void error() { + super.error(); + + if (G.onInquiry != null) { + G.onInquiry.OnInquiryError(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/response/ClientRegisterDeviceResponse.java b/app/src/main/java/net/iGap/response/ClientRegisterDeviceResponse.java new file mode 100644 index 0000000..1a122c8 --- /dev/null +++ b/app/src/main/java/net/iGap/response/ClientRegisterDeviceResponse.java @@ -0,0 +1,50 @@ +/* +* This is the source code of iGap for Android +* It is licensed under GNU AGPL v3.0 +* You should have received a copy of the license in this archive (see LICENSE). +* Copyright © 2017 , iGap - www.iGap.net +* iGap Messenger | Free, Fast and Secure instant messaging application +* The idea of the RooyeKhat Media Company - www.RooyeKhat.co +* All rights reserved. +*/ + +package net.iGap.response; + +import net.iGap.proto.ProtoClientRegisterDevice; +import net.iGap.proto.ProtoError; + +public class ClientRegisterDeviceResponse extends MessageHandler { + + public int actionId; + public Object message; + public Object identity; + + public ClientRegisterDeviceResponse(int actionId, Object protoClass, Object identity) { // here identity is roomId and messageId + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + ProtoClientRegisterDevice.ClientRegisterDeviceResponse.Builder builder = (ProtoClientRegisterDevice.ClientRegisterDeviceResponse.Builder) message; + } + + @Override + public void timeOut() { + super.timeOut(); + } + + @Override + public void error() { + super.error(); + ProtoError.ErrorResponse.Builder errorResponse = (ProtoError.ErrorResponse.Builder) message; + int majorCode = errorResponse.getMajorCode(); + int minorCode = errorResponse.getMinorCode(); + } +} + + diff --git a/app/src/main/java/net/iGap/response/GeoGetNearbyDistanceResponse.java b/app/src/main/java/net/iGap/response/GeoGetNearbyDistanceResponse.java index a10d04b..0859781 100644 --- a/app/src/main/java/net/iGap/response/GeoGetNearbyDistanceResponse.java +++ b/app/src/main/java/net/iGap/response/GeoGetNearbyDistanceResponse.java @@ -47,9 +47,11 @@ public void onInfo(RealmRegisteredInfo registeredInfo) { realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { - RealmGeoNearbyDistance geoNearbyDistance = realm.createObject(RealmGeoNearbyDistance.class, result.getUserId()); + RealmGeoNearbyDistance geoNearbyDistance = new RealmGeoNearbyDistance(); + geoNearbyDistance.setUserId(result.getUserId()); geoNearbyDistance.setHasComment(result.getHasComment()); geoNearbyDistance.setDistance(result.getDistance()); + realm.copyToRealmOrUpdate(geoNearbyDistance); } }); realm.close(); diff --git a/app/src/main/java/net/iGap/response/InfoPageResponse.java b/app/src/main/java/net/iGap/response/InfoPageResponse.java index 9bdd110..2efec9d 100644 --- a/app/src/main/java/net/iGap/response/InfoPageResponse.java +++ b/app/src/main/java/net/iGap/response/InfoPageResponse.java @@ -33,8 +33,17 @@ public void handler() { ProtoInfoPage.InfoPageResponse.Builder infoPageResponse = (ProtoInfoPage.InfoPageResponse.Builder) message; String body = infoPageResponse.getBody(); - if (G.onReceivePageInfoTOS != null) { - G.onReceivePageInfoTOS.onReceivePageInfo(body); + switch (identity) { + case "TOS": + if (G.onReceivePageInfoTOS != null) { + G.onReceivePageInfoTOS.onReceivePageInfo(body); + } + break; + case "WALLET_AGREEMENT": + if (G.onReceivePageInfoWalletAgreement != null) { + G.onReceivePageInfoWalletAgreement.onReceivePageInfo(body); + } + break; } } diff --git a/app/src/main/java/net/iGap/response/MessageHandler.java b/app/src/main/java/net/iGap/response/MessageHandler.java index 2cc8dc5..12f76c7 100644 --- a/app/src/main/java/net/iGap/response/MessageHandler.java +++ b/app/src/main/java/net/iGap/response/MessageHandler.java @@ -69,8 +69,10 @@ public void error() { HelperError.showSnackMessage(HelperError.getErrorFromCode(majorCode, minorCode), false); - HelperLog.setErrorLog("MessageHandler error majorCode : " + errorResponse.getMajorCode() + - " minorCode : " + errorResponse.getMinorCode() + " " + G.lookupMap.get(actionId)); + if (majorCode != 5) { + HelperLog.setErrorLog("MessageHandler error majorCode : " + errorResponse.getMajorCode() + + " minorCode : " + errorResponse.getMinorCode() + " " + G.lookupMap.get(actionId)); + } if (BuildConfig.DEBUG) { diff --git a/app/src/main/java/net/iGap/response/MplGetBillTokenResponse.java b/app/src/main/java/net/iGap/response/MplGetBillTokenResponse.java new file mode 100644 index 0000000..ede31bc --- /dev/null +++ b/app/src/main/java/net/iGap/response/MplGetBillTokenResponse.java @@ -0,0 +1,51 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.response; + +import net.iGap.G; +import net.iGap.proto.ProtoMplGetBillToken; + +public class MplGetBillTokenResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + + public MplGetBillTokenResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + ProtoMplGetBillToken.MplGetBillTokenResponse.Builder builder = (ProtoMplGetBillToken.MplGetBillTokenResponse.Builder) message; + + if (G.onPayment != null) { + G.onPayment.onBillToken(builder.getStatus(), builder.getToken(), builder.getExpireTime(), builder.getMessage()); + } + } + + @Override + public void timeOut() { + super.timeOut(); + } + + @Override + public void error() { + super.error(); + } +} + + diff --git a/app/src/main/java/net/iGap/response/MplGetTopupTokenResponse.java b/app/src/main/java/net/iGap/response/MplGetTopupTokenResponse.java new file mode 100644 index 0000000..a2c3ed4 --- /dev/null +++ b/app/src/main/java/net/iGap/response/MplGetTopupTokenResponse.java @@ -0,0 +1,51 @@ +/* +* This is the source code of iGap for Android +* It is licensed under GNU AGPL v3.0 +* You should have received a copy of the license in this archive (see LICENSE). +* Copyright © 2017 , iGap - www.iGap.net +* iGap Messenger | Free, Fast and Secure instant messaging application +* The idea of the RooyeKhat Media Company - www.RooyeKhat.co +* All rights reserved. +*/ + +package net.iGap.response; + +import net.iGap.G; +import net.iGap.proto.ProtoMplGetTopupToken; + +public class MplGetTopupTokenResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + + public MplGetTopupTokenResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + ProtoMplGetTopupToken.MplGetTopupTokenResponse.Builder builder = (ProtoMplGetTopupToken.MplGetTopupTokenResponse.Builder) message; + + if (G.onPayment != null) { + G.onPayment.onChargeToken(builder.getStatus(), builder.getToken(), builder.getExpireTime(), builder.getMessage()); + } + } + + @Override + public void timeOut() { + super.timeOut(); + } + + @Override + public void error() { + super.error(); + } +} + + diff --git a/app/src/main/java/net/iGap/response/PushWalletPaymentVerifiedResponse.java b/app/src/main/java/net/iGap/response/PushWalletPaymentVerifiedResponse.java new file mode 100644 index 0000000..4771efd --- /dev/null +++ b/app/src/main/java/net/iGap/response/PushWalletPaymentVerifiedResponse.java @@ -0,0 +1,57 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.response; + +import android.util.Log; + +import net.iGap.proto.ProtoError; +import net.iGap.proto.ProtoPushWalletPaymentVerified; + +public class PushWalletPaymentVerifiedResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + + public PushWalletPaymentVerifiedResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + ProtoPushWalletPaymentVerified.PushWalletPaymentVerifiedResponse.Builder builder = (ProtoPushWalletPaymentVerified.PushWalletPaymentVerifiedResponse.Builder) message; + builder.getToken(); + Log.i("CCCCCCCCCC", "onResponse url: " + builder.getToken()); + + } + + @Override + public void timeOut() { + super.timeOut(); + Log.i("CCCCCCCCCC", "timeOut: "); + } + + @Override + public void error() { + super.error(); + ProtoError.ErrorResponse.Builder errorResponse = (ProtoError.ErrorResponse.Builder) message; + int majorCode = errorResponse.getMajorCode(); + int minorCode = errorResponse.getMinorCode(); + Log.i("CCCCCCCCCC", " majorCode: " + majorCode); + } +} + + diff --git a/app/src/main/java/net/iGap/response/UserContactsGetListResponse.java b/app/src/main/java/net/iGap/response/UserContactsGetListResponse.java index 4e36558..dcb0175 100644 --- a/app/src/main/java/net/iGap/response/UserContactsGetListResponse.java +++ b/app/src/main/java/net/iGap/response/UserContactsGetListResponse.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ package net.iGap.response; diff --git a/app/src/main/java/net/iGap/response/UserLoginResponse.java b/app/src/main/java/net/iGap/response/UserLoginResponse.java index 670fb1e..518c3ff 100644 --- a/app/src/main/java/net/iGap/response/UserLoginResponse.java +++ b/app/src/main/java/net/iGap/response/UserLoginResponse.java @@ -20,6 +20,7 @@ import net.iGap.realm.RealmUserInfo; import net.iGap.request.RequestSignalingGetConfiguration; import net.iGap.request.RequestUserLogin; +import net.iGap.request.RequestWalletGetAccessToken; import io.realm.Realm; @@ -48,7 +49,13 @@ public void handler() { G.currentServerTime = builder.getResponse().getTimestamp(); G.bothChatDeleteTime = builder.getChatDeleteMessageForBothPeriod() * 1000; G.userLogin = true; + G.isMplActive = builder.getMplActive(); + G.isWalletActive = builder.getWalletActive(); + G.isWalletRegister = builder.getWalletAgreementAccepted(); + if (G.onPayment != null) { + G.onPayment.onFinance(G.isMplActive, G.isWalletActive); + } /** * get Signaling Configuration * (( hint : call following request after set G.userLogin=true )) @@ -63,6 +70,12 @@ public void handler() { WebSocketClient.waitingForReconnecting = false; WebSocketClient.allowForReconnecting = true; G.onUserLogin.onLogin(); + RealmUserInfo.sendPushNotificationToServer(); + + if (G.isWalletActive && G.isWalletRegister) { + new RequestWalletGetAccessToken().walletGetAccessToken(); + } + } @Override diff --git a/app/src/main/java/net/iGap/response/WalletGetAccessTokenResponse.java b/app/src/main/java/net/iGap/response/WalletGetAccessTokenResponse.java new file mode 100644 index 0000000..cf12052 --- /dev/null +++ b/app/src/main/java/net/iGap/response/WalletGetAccessTokenResponse.java @@ -0,0 +1,74 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.response; + +import android.util.Log; + +import net.iGap.G; +import net.iGap.eventbus.EventManager; +import net.iGap.eventbus.socketMessages; +import net.iGap.proto.ProtoError; +import net.iGap.proto.ProtoWalletGetAccessToken; + +import ir.radsense.raadcore.model.Auth; + +public class WalletGetAccessTokenResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + + public WalletGetAccessTokenResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + + ProtoWalletGetAccessToken.WalletGetAccessTokenResponse.Builder builder = (ProtoWalletGetAccessToken.WalletGetAccessTokenResponse.Builder) message; + Auth auth = new Auth(builder.getAccessToken(), "bearer"); + if (auth.getJWT() == null) { + return; + } + + G.jwt = builder.getAccessToken(); + + auth.save(); + G.handler.postDelayed(new Runnable() { + @Override + public void run() { + EventManager.getInstance().postEvent(EventManager.ON_ACCESS_TOKEN_RECIVE, socketMessages.SUCCESS); + } + }, 1000); + } + + @Override + public void timeOut() { + super.timeOut(); + EventManager.getInstance().postEvent(EventManager.ON_ACCESS_TOKEN_RECIVE, socketMessages.FAILED); + } + + @Override + public void error() { + super.error(); + ProtoError.ErrorResponse.Builder errorResponse = (ProtoError.ErrorResponse.Builder) message; + int majorCode = errorResponse.getMajorCode(); + int minorCode = errorResponse.getMinorCode(); + EventManager.getInstance().postEvent(EventManager.ON_ACCESS_TOKEN_RECIVE, socketMessages.FAILED); + } +} + + diff --git a/app/src/main/java/net/iGap/response/WalletIdMappingResponse.java b/app/src/main/java/net/iGap/response/WalletIdMappingResponse.java new file mode 100644 index 0000000..5d4300a --- /dev/null +++ b/app/src/main/java/net/iGap/response/WalletIdMappingResponse.java @@ -0,0 +1,78 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.response; + +import android.util.Log; + +import net.iGap.helper.HelperPublicMethod; +import net.iGap.proto.ProtoError; +import net.iGap.proto.ProtoWalletIdMapping; + +import org.paygear.wallet.RaadApp; + +public class WalletIdMappingResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + public boolean isDeleted = false; + + public WalletIdMappingResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + + ProtoWalletIdMapping.WalletIdMappingResponse.Builder builder = (ProtoWalletIdMapping.WalletIdMappingResponse.Builder) message; + builder.getUserId(); + + HelperPublicMethod.goToChatRoom(builder.getUserId(), new HelperPublicMethod.OnComplete() { + @Override + public void complete() { + + if (RaadApp.paygearHistoryCloseWallet != null) + RaadApp.paygearHistoryCloseWallet.closeWallet(); + + } + }, new HelperPublicMethod.OnError() { + @Override + public void error() { + + } + }); + Log.i("CCCCCCCCC", "4 handler:+ " + builder.getUserId()); + } + + @Override + public void timeOut() { + super.timeOut(); + Log.i("CCCCCCCCC", "6 majorCode:+ "); + if (RaadApp.paygearHistoryCloseWallet != null) RaadApp.paygearHistoryCloseWallet.error(); + } + + @Override + public void error() { + super.error(); + ProtoError.ErrorResponse.Builder errorResponse = (ProtoError.ErrorResponse.Builder) message; + int majorCode = errorResponse.getMajorCode(); + int minorCode = errorResponse.getMinorCode(); + Log.i("CCCCCCCCC", "5 majorCode:+ " + majorCode); + if (RaadApp.paygearHistoryCloseWallet != null) RaadApp.paygearHistoryCloseWallet.error(); + } +} + + diff --git a/app/src/main/java/net/iGap/response/WalletPaymentInitResponse.java b/app/src/main/java/net/iGap/response/WalletPaymentInitResponse.java new file mode 100644 index 0000000..b8450c8 --- /dev/null +++ b/app/src/main/java/net/iGap/response/WalletPaymentInitResponse.java @@ -0,0 +1,58 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.response; + +import net.iGap.eventbus.EventManager; +import net.iGap.proto.ProtoError; +import net.iGap.proto.ProtoWalletPaymentInit; + +public class WalletPaymentInitResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + + public WalletPaymentInitResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + } + + @Override + public void handler() { + super.handler(); + + ProtoWalletPaymentInit.WalletPaymentInitResponse.Builder builder = (ProtoWalletPaymentInit.WalletPaymentInitResponse.Builder) message; + builder.getToken(); + builder.getPublicKey(); + EventManager.getInstance().postEvent(EventManager.ON_INIT_PAY, builder); + } + + @Override + public void timeOut() { + super.timeOut(); + EventManager.getInstance().postEvent(EventManager.ON_INIT_PAY, null); + } + + @Override + public void error() { + super.error(); + ProtoError.ErrorResponse.Builder errorResponse = (ProtoError.ErrorResponse.Builder) message; + int majorCode = errorResponse.getMajorCode(); + int minorCode = errorResponse.getMinorCode(); + + EventManager.getInstance().postEvent(EventManager.ON_INIT_PAY, null); + } +} + + diff --git a/app/src/main/java/net/iGap/response/WalletRegisterResponse.java b/app/src/main/java/net/iGap/response/WalletRegisterResponse.java new file mode 100644 index 0000000..f48a68c --- /dev/null +++ b/app/src/main/java/net/iGap/response/WalletRegisterResponse.java @@ -0,0 +1,50 @@ +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +package net.iGap.response; + +import net.iGap.G; +import net.iGap.fragments.FragmentWallet; +import net.iGap.helper.HelperFragment; +import net.iGap.proto.ProtoWalletRegister; +import net.iGap.request.RequestWalletGetAccessToken; + +public class WalletRegisterResponse extends MessageHandler { + + public int actionId; + public Object message; + public String identity; + + public WalletRegisterResponse(int actionId, Object protoClass, String identity) { + super(actionId, protoClass, identity); + + this.message = protoClass; + this.actionId = actionId; + this.identity = identity; + new RequestWalletGetAccessToken().walletGetAccessToken(); + } + + @Override + public void handler() { + super.handler(); + ProtoWalletRegister.WalletRegisterResponse.Builder builder = (ProtoWalletRegister.WalletRegisterResponse.Builder) message; + G.isWalletRegister = true; + } + + @Override + public void timeOut() { + super.timeOut(); + } + + @Override + public void error() { + super.error(); + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/viewmodel/ActivityCallViewModel.java b/app/src/main/java/net/iGap/viewmodel/ActivityCallViewModel.java index 7eb8e24..c88a86d 100644 --- a/app/src/main/java/net/iGap/viewmodel/ActivityCallViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/ActivityCallViewModel.java @@ -478,7 +478,7 @@ private void loadOrDownloadPicture(RealmRegisteredInfo registeredInfo) { ProtoFileDownload.FileDownload.Selector se = ProtoFileDownload.FileDownload.Selector.FILE; String dirPath = AndroidUtils.getFilePathWithCashId(av.getCacheId(), av.getName(), G.DIR_IMAGE_USER, false); - HelperDownloadFile.startDownload(System.currentTimeMillis() + "", av.getToken(), av.getUrl(), av.getCacheId(), av.getName(), av.getSize(), se, dirPath, 4, new HelperDownloadFile.UpdateListener() { + HelperDownloadFile.getInstance().startDownload(System.currentTimeMillis() + "", av.getToken(), av.getUrl(), av.getCacheId(), av.getName(), av.getSize(), se, dirPath, 4, new HelperDownloadFile.UpdateListener() { @Override public void OnProgress(final String path, int progress) { if (progress == 100) { @@ -507,10 +507,21 @@ private void muteMusic() { if (!isMuteAllMusic) { AudioManager am = (AudioManager) G.context.getSystemService(Context.AUDIO_SERVICE); - musicVolum = am.getStreamVolume(AudioManager.STREAM_MUSIC); - am.setStreamMute(AudioManager.STREAM_MUSIC, true); - am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); - isMuteAllMusic = true; + if (am == null) { + return; + } + int result = am.requestAudioFocus(new AudioManager.OnAudioFocusChangeListener() { + @Override + public void onAudioFocusChange(int focusChange) { + + } + }, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); + if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { + musicVolum = am.getStreamVolume(AudioManager.STREAM_MUSIC); + am.setStreamMute(AudioManager.STREAM_MUSIC, true); + am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); + isMuteAllMusic = true; + } } } @@ -518,9 +529,11 @@ private void unMuteMusic() { if (isMuteAllMusic) { AudioManager am = (AudioManager) G.context.getSystemService(Context.AUDIO_SERVICE); - am.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolum, 0); - am.setStreamMute(AudioManager.STREAM_MUSIC, false); - isMuteAllMusic = false; + if (am != null) { + am.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolum, 0); + am.setStreamMute(AudioManager.STREAM_MUSIC, false); + isMuteAllMusic = false; + } } } diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentChannelProfileViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentChannelProfileViewModel.java index 6376148..5444a2f 100644 --- a/app/src/main/java/net/iGap/viewmodel/FragmentChannelProfileViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/FragmentChannelProfileViewModel.java @@ -15,6 +15,7 @@ import android.content.DialogInterface; import android.databinding.ObservableBoolean; import android.databinding.ObservableField; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; @@ -63,7 +64,6 @@ import net.iGap.interfaces.OnChannelDelete; import net.iGap.interfaces.OnChannelEdit; import net.iGap.interfaces.OnChannelKickAdmin; -import net.iGap.interfaces.OnChannelKickMember; import net.iGap.interfaces.OnChannelKickModerator; import net.iGap.interfaces.OnChannelLeft; import net.iGap.interfaces.OnChannelRemoveUsername; @@ -525,7 +525,7 @@ private void dialogRevoke() { final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.channel_link_title_revoke)) .positiveText(G.fragmentActivity.getResources().getString(R.string.revoke)) .customView(layoutRevoke, true) - .widgetColor(G.context.getResources().getColor(R.color.toolbar_background)) + .widgetColor(Color.parseColor(G.appBarColor)) .negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)) .neutralText(R.string.array_Copy) .onNeutral(new MaterialDialog.SingleButtonCallback() { @@ -593,7 +593,7 @@ private void dialogCopyLink() { final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.channel_link)) .positiveText(G.fragmentActivity.getResources().getString(R.string.array_Copy)) .customView(layoutChannelLink, true) - .widgetColor(G.context.getResources().getColor(R.color.toolbar_background)) + .widgetColor(Color.parseColor(G.appBarColor)) .negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override @@ -701,7 +701,7 @@ private void channelAddMemberResponse(long roomIdResponse, final long userId, fi //********** dialog for edit channel private void ChangeGroupDescription(final View v) { - MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(R.string.channel_description).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).alwaysCallInputCallback().widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).onPositive(new MaterialDialog.SingleButtonCallback() { + MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(R.string.channel_description).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).alwaysCallInputCallback().widgetColor(Color.parseColor(G.appBarColor)).onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { editChannelRequest(callbackChannelName.get(), dialogDesc); @@ -764,7 +764,7 @@ private void ChangeGroupName(final View v) { layoutUserName.addView(inputUserName, layoutParams); final MaterialDialog dialog = - new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.channel_name)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.channel_name)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); final View positive = dialog.getActionButton(DialogAction.POSITIVE); @@ -839,7 +839,7 @@ public void onClick(View view) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewUserName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } @@ -1128,7 +1128,7 @@ private void setUsername(final View v) { layoutUserName.addView(inputUserName, layoutParams); final MaterialDialog dialog = - new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_username)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_username)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); final View positive = dialog.getActionButton(DialogAction.POSITIVE); positive.setEnabled(false); @@ -1268,7 +1268,7 @@ public void onClick(View view) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewUserName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentCreateChannelViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentCreateChannelViewModel.java index d5f6210..be05df2 100644 --- a/app/src/main/java/net/iGap/viewmodel/FragmentCreateChannelViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/FragmentCreateChannelViewModel.java @@ -12,6 +12,7 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.databinding.ObservableField; +import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.PopupMenu; @@ -50,7 +51,7 @@ public class FragmentCreateChannelViewModel implements OnChannelCheckUsername { public Spannable wordtoSpan; public ObservableField edtSetLink = new ObservableField<>(Config.IGAP_LINK_PREFIX); public ObservableField prgWaiting = new ObservableField<>(View.GONE); - public ObservableField txtFinishColor = new ObservableField<>(G.context.getResources().getColor(R.color.toolbar_background)); + public ObservableField txtFinishColor = new ObservableField<>(Color.parseColor(G.appBarColor)); public ObservableField txtInputLinkEnable = new ObservableField<>(false); public ObservableField txtFinishEnable = new ObservableField<>(true); public ObservableField edtSetLinkEnable = new ObservableField<>(true); @@ -262,7 +263,7 @@ private void setInviteLink() { edtSetLink.set(inviteLink); edtSetLinkEnable.set(false); txtFinishEnable.set(true); - txtFinishColor.set(G.context.getResources().getColor(R.color.toolbar_background)); + txtFinishColor.set(Color.parseColor(G.appBarColor)); txtInputLinkEnable.set(true); fragmentCreateChannelBinding.fchTxtInputNikeName.setError(""); } else if (isRadioButtonPublic.get()) { @@ -282,7 +283,7 @@ public void run() { if (status == ProtoChannelCheckUsername.ChannelCheckUsernameResponse.Status.AVAILABLE) { txtFinishEnable.set(true); - txtFinishColor.set(G.context.getResources().getColor(R.color.toolbar_background)); + txtFinishColor.set(Color.parseColor(G.appBarColor)); txtInputLinkEnable.set(true); fragmentCreateChannelBinding.fchTxtInputNikeName.setError(""); } else if (status == ProtoChannelCheckUsername.ChannelCheckUsernameResponse.Status.INVALID) { diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentDarkThemeViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentDarkThemeViewModel.java index 6cc861c..44ad208 100644 --- a/app/src/main/java/net/iGap/viewmodel/FragmentDarkThemeViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/FragmentDarkThemeViewModel.java @@ -1,27 +1,19 @@ package net.iGap.viewmodel; import android.app.TimePickerDialog; -import android.content.Context; import android.content.SharedPreferences; -import android.databinding.BaseObservable; -import android.databinding.Bindable; import android.databinding.ObservableField; -import android.os.SystemClock; -import android.util.Log; import android.view.View; import android.widget.TimePicker; import net.iGap.G; import net.iGap.R; +import net.iGap.Theme; import net.iGap.fragments.FragmentDarkTheme; import net.iGap.module.SHP_SETTING; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - import static android.content.Context.MODE_PRIVATE; +import static net.iGap.viewmodel.FragmentThemColorViewModel.resetApp; /* * This is the source code of iGap for Android @@ -83,6 +75,23 @@ private void getInfo() { } + public void onClickSetTheme(View view) { + SharedPreferences.Editor editor; + if (sharedPreferences == null) { + SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); + editor = sharedPreferences.edit(); + } else { + editor = sharedPreferences.edit(); + } + editor.putInt(SHP_SETTING.KEY_THEME_COLOR, Theme.DARK); + editor.putBoolean(SHP_SETTING.KEY_THEME_DARK, true); + editor.apply(); + + Theme.setThemeColor(); + resetApp(); + + } + public void onClickDisable(View v) { SharedPreferences.Editor editor = sharedPreferences.edit(); @@ -161,4 +170,6 @@ public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinut mTimePicker.show(); } + + } diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentGroupProfileViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentGroupProfileViewModel.java index f5bc51f..98862bf 100644 --- a/app/src/main/java/net/iGap/viewmodel/FragmentGroupProfileViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/FragmentGroupProfileViewModel.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.DialogInterface; import android.databinding.ObservableField; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; @@ -515,7 +516,7 @@ private void setUsername(final View v) { layoutUserName.addView(inputUserName, layoutParams); final MaterialDialog dialog = - new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_username)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_username)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); final View positive = dialog.getActionButton(DialogAction.POSITIVE); positive.setEnabled(false); @@ -644,7 +645,7 @@ public void onClick(View view) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewUserName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } @@ -891,7 +892,7 @@ private void dialogRevoke() { final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.group_link_hint_revoke)) .positiveText(G.fragmentActivity.getResources().getString(R.string.revoke)) .customView(layoutRevoke, true) - .widgetColor(G.context.getResources().getColor(R.color.toolbar_background)) + .widgetColor(Color.parseColor(G.appBarColor)) .negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)) .neutralText(R.string.array_Copy) .onNeutral(new MaterialDialog.SingleButtonCallback() { @@ -957,7 +958,7 @@ private void dialogCopyLink() { final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.group_link)) .positiveText(G.fragmentActivity.getResources().getString(R.string.array_Copy)) .customView(layoutGroupLink, true) - .widgetColor(G.context.getResources().getColor(R.color.toolbar_background)) + .widgetColor(Color.parseColor(G.appBarColor)) .negativeText(G.fragmentActivity.getResources().getString(R.string.no)) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override @@ -1188,7 +1189,7 @@ private void ChangeGroupName(final View view) { layoutUserName.addView(inputUserName, layoutParams); final MaterialDialog dialog = - new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.group_name)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.group_name)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); final View positive = dialog.getActionButton(DialogAction.POSITIVE); positive.setEnabled(false); @@ -1258,7 +1259,7 @@ public void onClick(View view) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewUserName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } @@ -1276,7 +1277,7 @@ public void onDismiss(DialogInterface dialog) { } private void ChangeGroupDescription() { - MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(R.string.group_description).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).alwaysCallInputCallback().widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).onPositive(new MaterialDialog.SingleButtonCallback() { + MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(R.string.group_description).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).alwaysCallInputCallback().widgetColor(Color.parseColor(G.appBarColor)).onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentLanguageViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentLanguageViewModel.java index ed8d7a1..6d9f480 100644 --- a/app/src/main/java/net/iGap/viewmodel/FragmentLanguageViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/FragmentLanguageViewModel.java @@ -10,7 +10,6 @@ */ import android.content.SharedPreferences; -import android.content.res.Configuration; import android.view.View; import net.iGap.G; @@ -46,19 +45,17 @@ public void onClickEnglish(View v) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(SHP_SETTING.KEY_LANGUAGE, "English"); editor.apply(); - setLocale("en"); + G.selectedLanguage = "en"; + G.updateResources(G.currentActivity); HelperCalander.isPersianUnicode = false; HelperCalander.isLanguagePersian = false; HelperCalander.isLanguageArabic = false; G.isAppRtl = false; - if (onRefreshActivity != null) { FragmentLanguage.languageChanged = true; G.isRestartActivity = true; onRefreshActivity.refresh("en"); } - - G.selectedLanguage = "en"; } if (MusicPlayer.updateName != null) { @@ -75,7 +72,7 @@ public void onClickFarsi(View v) { editor.putString(SHP_SETTING.KEY_LANGUAGE, "فارسی"); editor.apply(); G.selectedLanguage = "fa"; - setLocale("fa"); + G.updateResources(G.currentActivity); HelperCalander.isPersianUnicode = true; HelperCalander.isLanguagePersian = true; HelperCalander.isLanguageArabic = false; @@ -102,7 +99,7 @@ public void onClickArabi(View v) { editor.putString(SHP_SETTING.KEY_LANGUAGE, "العربی"); editor.apply(); G.selectedLanguage = "ar"; - setLocale("ar"); + G.updateResources(G.currentActivity); HelperCalander.isPersianUnicode = true; HelperCalander.isLanguagePersian = false; HelperCalander.isLanguageArabic = true; @@ -144,13 +141,5 @@ private void getInfo() { textLanguage = sharedPreferences.getString(SHP_SETTING.KEY_LANGUAGE, Locale.getDefault().getDisplayLanguage()); } - public void setLocale(String lang) { - Locale locale = new Locale(lang); - Locale.setDefault(locale); - Configuration config = new Configuration(); - config.locale = locale; - G.fragmentActivity.getBaseContext().getResources().updateConfiguration(config, G.fragmentActivity.getBaseContext().getResources().getDisplayMetrics()); - } - } diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentNotificationAndSoundViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentNotificationAndSoundViewModel.java index 1aaf143..3cd940f 100644 --- a/app/src/main/java/net/iGap/viewmodel/FragmentNotificationAndSoundViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/FragmentNotificationAndSoundViewModel.java @@ -64,6 +64,11 @@ public class FragmentNotificationAndSoundViewModel { private int modeGroup; private int poRbDialogSoundMessageGroup; private String soundMessageGroup; + private String soundMessageSelected = ""; + private String soundMessageGroupSelected = ""; + private int soundMessageWhich = 0; + private int soundMessageGroupWhich = 0; + public FragmentNotificationAndSoundViewModel(FragmentNotificationAndSoundBinding fragmentNotificationAndSoundBinding) { @@ -437,61 +442,25 @@ public void onClickSoundMessage(View view) { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { - switch (which) { - case 0: - MediaPlayer.create(G.fragmentActivity, R.raw.igap).start(); - break; - case 1: - MediaPlayer.create(G.fragmentActivity, R.raw.aooow).start(); - break; - case 2: - MediaPlayer.create(G.fragmentActivity, R.raw.bbalert).start(); - break; - case 3: - MediaPlayer.create(G.fragmentActivity, R.raw.boom).start(); - break; - case 4: - MediaPlayer.create(G.fragmentActivity, R.raw.bounce).start(); - break; - case 5: - MediaPlayer.create(G.fragmentActivity, R.raw.doodoo).start(); - break; + playSound(which); - case 6: - MediaPlayer.create(G.fragmentActivity, R.raw.jing).start(); - break; - case 7: - MediaPlayer.create(G.fragmentActivity, R.raw.lili).start(); - break; - case 8: - MediaPlayer.create(G.fragmentActivity, R.raw.msg).start(); - break; - case 9: - MediaPlayer.create(G.fragmentActivity, R.raw.newa).start(); - break; - case 10: - MediaPlayer.create(G.fragmentActivity, R.raw.none).start(); - break; - case 11: - MediaPlayer.create(G.fragmentActivity, R.raw.onelime).start(); - break; - case 12: - MediaPlayer.create(G.fragmentActivity, R.raw.tone).start(); - break; - case 13: - MediaPlayer.create(G.fragmentActivity, R.raw.woow).start(); - break; - } + soundMessageSelected = text.toString(); + soundMessageWhich = which; - callbackSoundMessage.set(text.toString()); - poRbDialogSoundMessage = which; - editor.putInt(SHP_SETTING.KEY_STNS_SOUND_MESSAGE_POSITION, which); - editor.putString(SHP_SETTING.KEY_STNS_SOUND_MESSAGE, text.toString()); + return true; + } + }).positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + + callbackSoundMessage.set(soundMessageSelected); + poRbDialogSoundMessage = soundMessageWhich; + editor.putInt(SHP_SETTING.KEY_STNS_SOUND_MESSAGE_POSITION, soundMessageWhich); + editor.putString(SHP_SETTING.KEY_STNS_SOUND_MESSAGE, soundMessageSelected); editor.apply(); - return true; } - }).positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).show(); + }).show(); } @@ -616,61 +585,27 @@ public void onClickSoundGroup(View view) { new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.Ringtone)).titleGravity(GravityEnum.START).titleColor(G.context.getResources().getColor(android.R.color.black)).items(R.array.sound_message).alwaysCallSingleChoiceCallback().itemsCallbackSingleChoice(poRbDialogSoundMessageGroup, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { - switch (which) { - case 0: - MediaPlayer.create(G.fragmentActivity, R.raw.igap).start(); - break; - case 1: - MediaPlayer.create(G.fragmentActivity, R.raw.aooow).start(); - break; - case 2: - MediaPlayer.create(G.fragmentActivity, R.raw.bbalert).start(); - break; - case 3: - MediaPlayer.create(G.fragmentActivity, R.raw.boom).start(); - break; - case 4: - MediaPlayer.create(G.fragmentActivity, R.raw.bounce).start(); - break; - case 5: - MediaPlayer.create(G.fragmentActivity, R.raw.doodoo).start(); - break; - case 6: - MediaPlayer.create(G.fragmentActivity, R.raw.jing).start(); - break; - case 7: - MediaPlayer.create(G.fragmentActivity, R.raw.lili).start(); - break; - case 8: - MediaPlayer.create(G.fragmentActivity, R.raw.msg).start(); - break; - case 9: - MediaPlayer.create(G.fragmentActivity, R.raw.newa).start(); - break; - case 10: - MediaPlayer.create(G.fragmentActivity, R.raw.none).start(); - break; - case 11: - MediaPlayer.create(G.fragmentActivity, R.raw.onelime).start(); - break; - case 12: - MediaPlayer.create(G.fragmentActivity, R.raw.tone).start(); - break; - case 13: - MediaPlayer.create(G.fragmentActivity, R.raw.woow).start(); - break; - } + playSound(which); - callBackSoundGroup.set(text.toString()); - poRbDialogSoundMessageGroup = which; + soundMessageGroupSelected = text.toString(); + soundMessageGroupWhich = which; - editor.putString(SHP_SETTING.KEY_STNS_SOUND_GROUP, text.toString()); - editor.putInt(SHP_SETTING.KEY_STNS_SOUND_GROUP_POSITION, which); - editor.apply(); return true; } - }).positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).show(); + }).positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + + callBackSoundGroup.set(soundMessageGroupSelected); + poRbDialogSoundMessageGroup = soundMessageGroupWhich; + + editor.putString(SHP_SETTING.KEY_STNS_SOUND_GROUP, soundMessageGroupSelected); + editor.putInt(SHP_SETTING.KEY_STNS_SOUND_GROUP_POSITION, soundMessageGroupWhich); + editor.apply(); + + } + }).show(); } public void onClickInAppSound(View view) { @@ -758,4 +693,67 @@ private void getInfo() { } + private void playSound(int which) { + + int musicId = R.raw.igap; + + switch (which) { + case 0: + musicId = R.raw.igap; + break; + case 1: + musicId = R.raw.aooow; + break; + case 2: + musicId = R.raw.bbalert; + break; + case 3: + musicId = R.raw.boom; + break; + case 4: + musicId = R.raw.bounce; + break; + case 5: + musicId = R.raw.doodoo; + break; + case 6: + musicId = R.raw.jing; + break; + case 7: + musicId = R.raw.lili; + break; + case 8: + musicId = R.raw.msg; + break; + case 9: + musicId = R.raw.newa; + break; + case 10: + musicId = R.raw.none; + break; + case 11: + musicId = R.raw.onelime; + break; + case 12: + musicId = R.raw.tone; + break; + case 13: + musicId = R.raw.woow; + break; + } + + + MediaPlayer mediaPlayer = MediaPlayer.create(G.fragmentActivity, musicId); + mediaPlayer.start(); + + mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + public void onCompletion(MediaPlayer mp) { + mp.release(); + } + + ; + }); + + } + } diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentPaymentBillViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentPaymentBillViewModel.java new file mode 100644 index 0000000..a8b09bb --- /dev/null +++ b/app/src/main/java/net/iGap/viewmodel/FragmentPaymentBillViewModel.java @@ -0,0 +1,192 @@ +package net.iGap.viewmodel; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. +*/ + +import android.databinding.ObservableBoolean; +import android.databinding.ObservableField; +import android.databinding.ObservableInt; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.view.View; + +import com.google.zxing.integration.android.IntentIntegrator; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.databinding.FragmentPaymentBillBinding; +import net.iGap.fragments.FragmentPaymentBill; +import net.iGap.helper.HelperError; +import net.iGap.helper.HelperPermission; +import net.iGap.interfaces.OnGetPermission; +import net.iGap.interfaces.OnMplResult; +import net.iGap.request.RequestMplGetBillToken; + +import java.io.IOException; + +import static net.iGap.activities.ActivityMain.requestCodeBarcode; + + +public class FragmentPaymentBillViewModel { + + private FragmentPaymentBill fragmentPaymentBill; + private FragmentPaymentBillBinding fragmentPaymentBillBinding; + public ObservableInt observeCompany = new ObservableInt(View.GONE); + public ObservableField observeTitleToolbar = new ObservableField<>(""); + public ObservableBoolean observePolice = new ObservableBoolean(false); + public ObservableBoolean observeEnabledPayment = new ObservableBoolean(true); + public ObservableBoolean observeAmount = new ObservableBoolean(false); + + public ObservableField observeBackGround = new ObservableField<>(); + + private boolean isPolice = false; + + public FragmentPaymentBillViewModel(FragmentPaymentBill fragmentPaymentBill, FragmentPaymentBillBinding fragmentPaymentBillBinding, int resTitleId) { + this.fragmentPaymentBill = fragmentPaymentBill; + this.fragmentPaymentBillBinding = fragmentPaymentBillBinding; + observeTitleToolbar.set(G.context.getString(resTitleId)); + + isPolice = resTitleId == R.string.pay_bills_crime; + + if (isPolice) { + observePolice.set(true); + observeAmount.set(false); + } + + Drawable myIcon = G.context.getResources().getDrawable(R.drawable.oval_green); + myIcon.setColorFilter(Color.parseColor(G.appBarColor), PorterDuff.Mode.SRC_IN); + observeBackGround.set(myIcon); + } + + + public void onTextChangedBillId(CharSequence s, int start, int before, int count) { + if (isPolice) { + return; + } + if (s.length() == 13) { + observeCompany.set(View.VISIBLE); + fragmentPaymentBillBinding.fpbImvCompany.setImageResource(getCompany(s.toString().substring(11, 12))); + } else { + observeCompany.set(View.GONE); + } + } + + + public void onClickBarCode(View v) { + + try { + HelperPermission.getCameraPermission(G.currentActivity, new OnGetPermission() { + @Override + public void Allow() throws IOException, IllegalStateException { + IntentIntegrator integrator = IntentIntegrator.forSupportFragment(fragmentPaymentBill); + integrator.setDesiredBarcodeFormats(IntentIntegrator.CODE_128); + integrator.setRequestCode(requestCodeBarcode); + integrator.setBeepEnabled(false); + integrator.setPrompt(""); + integrator.initiateScan(); + } + + @Override + public void deny() { + } + }); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public void onPayBillClick(View v) { + + if (!G.userLogin) { + HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); + return; + } + + String billId = fragmentPaymentBillBinding.fpbEdtBillId.getText().toString(); + + if (isPolice) { + if (billId.length() == 0) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.biling_id_not_valid), false); + return; + } + + } else { + if (billId.length() != 13) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.biling_id_not_valid), false); + return; + } + } + + + String payId = fragmentPaymentBillBinding.fpbEdtPayId.getText().toString(); + + if (isPolice) { + if (payId.length() == 0) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.pay_id_is_not_valid), false); + return; + } + } else { + if (payId.length() > 13 || payId.length() < 5) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.pay_id_is_not_valid), false); + return; + } + } + + + G.onMplResult = new OnMplResult() { + @Override + public void onResult(boolean error) { + + if (error) { + observeEnabledPayment.set(true); + } else { + fragmentPaymentBillBinding.getBackHandler().onBack(); + } + + } + }; + + RequestMplGetBillToken requestMplGetBillToken = new RequestMplGetBillToken(); + requestMplGetBillToken.mplGetBillToken(Long.parseLong(billId), Long.parseLong(payId)); + + observeEnabledPayment.set(false); + } + + + public static int getCompany(String value) { + + int result = 0; + switch (value) { + case "1": + result = R.drawable.bill_water_pec; + break; + case "2": + result = R.drawable.bill_elc_pec; + break; + case "3": + result = R.drawable.bill_gaz_pec; + break; + case "4": + result = R.drawable.bill_telecom_pec; + break; + case "5": + result = R.drawable.bill_mci_pec; + break; + case "6": + result = R.drawable.bill_shahrdari_pec; + break; + } + + return result; + } + + +} diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentPaymentChargeViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentPaymentChargeViewModel.java new file mode 100644 index 0000000..eeab417 --- /dev/null +++ b/app/src/main/java/net/iGap/viewmodel/FragmentPaymentChargeViewModel.java @@ -0,0 +1,338 @@ +package net.iGap.viewmodel; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. +*/ + +import android.content.Context; +import android.databinding.ObservableBoolean; +import android.databinding.ObservableField; +import android.databinding.ObservableInt; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.databinding.FragmentPaymentChargeBinding; +import net.iGap.helper.HelperError; +import net.iGap.interfaces.OnMplResult; +import net.iGap.proto.ProtoMplGetTopupToken; +import net.iGap.request.RequestMplGetTopupToken; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + + +public class FragmentPaymentChargeViewModel { + + public enum OperatorType { + HAMRAH_AVAL, IRANCELL, RITEL; + } + + HashMap phoneMap = new HashMap() { + { + put("0910", OperatorType.HAMRAH_AVAL); + put("0911", OperatorType.HAMRAH_AVAL); + put("0912", OperatorType.HAMRAH_AVAL); + put("0913", OperatorType.HAMRAH_AVAL); + put("0914", OperatorType.HAMRAH_AVAL); + put("0915", OperatorType.HAMRAH_AVAL); + put("0916", OperatorType.HAMRAH_AVAL); + put("0917", OperatorType.HAMRAH_AVAL); + put("0918", OperatorType.HAMRAH_AVAL); + put("0919", OperatorType.HAMRAH_AVAL); + put("0990", OperatorType.HAMRAH_AVAL); + put("0991", OperatorType.HAMRAH_AVAL); + + put("0901", OperatorType.IRANCELL); + put("0902", OperatorType.IRANCELL); + put("0903", OperatorType.IRANCELL); + put("0930", OperatorType.IRANCELL); + put("0933", OperatorType.IRANCELL); + put("0935", OperatorType.IRANCELL); + put("0936", OperatorType.IRANCELL); + put("0937", OperatorType.IRANCELL); + put("0938", OperatorType.IRANCELL); + put("0939", OperatorType.IRANCELL); + + put("0920", OperatorType.RITEL); + put("0921", OperatorType.RITEL); + put("0922", OperatorType.RITEL); + + } + }; + + private FragmentPaymentChargeBinding fragmentPaymentChargeBinding; + private OperatorType operatorType; + + public ObservableInt observeTarabord = new ObservableInt(View.GONE); + public ObservableField observeBackGround = new ObservableField<>(); + public ObservableBoolean observeEnabledPayment = new ObservableBoolean(true); + + public ObservableInt observeChargeTypeHint = new ObservableInt(View.VISIBLE); + public ObservableInt observePriceHint = new ObservableInt(View.VISIBLE); + + + public FragmentPaymentChargeViewModel(FragmentPaymentChargeBinding fragmentPaymentChargeBinding) { + this.fragmentPaymentChargeBinding = fragmentPaymentChargeBinding; + + Drawable myIcon = G.context.getResources().getDrawable(R.drawable.oval_green); + myIcon.setColorFilter(Color.parseColor(G.appBarColor), PorterDuff.Mode.SRC_IN); + observeBackGround.set(myIcon); + setAdapterOperatorType(); + } + + + //**************************************************************************************** + + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (s.length() == 11) { + if (fragmentPaymentChargeBinding.fpcCheckBoxTrabord.isChecked()) { + fragmentPaymentChargeBinding.fpcCheckBoxTrabord.setChecked(false); + } else { + setOperator(s.toString()); + } + } + } + + public void checkBoxTarabordChanged(View v, boolean checked) { + if (checked) { + observeTarabord.set(View.VISIBLE); + fragmentPaymentChargeBinding.fpcSpinnerOperator.setSelection(0); + + } else { + observeTarabord.set(View.GONE); + setOperator(fragmentPaymentChargeBinding.fpcEditTextPhoneNumber.getText().toString()); + } + } + + public void onItemSelecteSpinerOperator(AdapterView parent, View view, int position, long id) { + switch (position) { + case 0: + operatorType = null; + fragmentPaymentChargeBinding.fpcSpinnerChargeType.setAdapter(null); + fragmentPaymentChargeBinding.fpcSpinnerPrice.setAdapter(null); + observeChargeTypeHint.set(View.VISIBLE); + observePriceHint.set(View.VISIBLE); + break; + case 1: + setAdapterValue(OperatorType.HAMRAH_AVAL); + break; + case 2: + setAdapterValue(OperatorType.IRANCELL); + break; + case 3: + setAdapterValue(OperatorType.RITEL); + break; + } + } + + //****************************************************************************************************** + + private void setOperator(String phone) { + if (phone.length() == 11) { + String s = phone.substring(0, 4); + OperatorType opt = phoneMap.get(s); + if (opt != null) { + setAdapterValue(opt); + } else { + observeTarabord.set(View.VISIBLE); + } + } + } + + private void setAdapterValue(OperatorType operator) { + switch (operator) { + case HAMRAH_AVAL: + operatorType = OperatorType.HAMRAH_AVAL; + onOpereatorChange(R.array.charge_type_hamrahe_aval); + onPriceChange(R.array.charge_price); + break; + case IRANCELL: + operatorType = OperatorType.IRANCELL; + onOpereatorChange(R.array.charge_type_irancell); + onPriceChange(R.array.charge_price_irancell); + break; + case RITEL: + operatorType = OperatorType.RITEL; + onOpereatorChange(R.array.charge_type_ritel); + onPriceChange(R.array.charge_price); + break; + } + } + + private void onOpereatorChange(int arrayId) { + ArrayAdapter adapter = ArrayAdapter.createFromResource(G.context, arrayId, R.layout.spinner_item_custom); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + fragmentPaymentChargeBinding.fpcSpinnerChargeType.setAdapter(adapter); + fragmentPaymentChargeBinding.fpcSpinnerChargeType.setSelection(0); + observeChargeTypeHint.set(View.GONE); + } + + private void onPriceChange(int arrayId) { + ArrayAdapter adapter = ArrayAdapter.createFromResource(G.context, arrayId, R.layout.spinner_item_custom); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + fragmentPaymentChargeBinding.fpcSpinnerPrice.setAdapter(adapter); + fragmentPaymentChargeBinding.fpcSpinnerPrice.setSelection(0); + observePriceHint.set(View.GONE); + } + + private void setAdapterOperatorType() { + MySpinnerAdapter adapter = new MySpinnerAdapter(G.context, R.layout.spinner_item_custom, Arrays.asList(G.context.getResources().getTextArray(R.array.phone_operator))); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + fragmentPaymentChargeBinding.fpcSpinnerOperator.setAdapter(adapter); + fragmentPaymentChargeBinding.fpcSpinnerOperator.setSelection(0); + } + + + public void onBuyClick(View v) { + + if (!G.userLogin) { + HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); + return; + } + + String phoneNumber = fragmentPaymentChargeBinding.fpcEditTextPhoneNumber.getText().toString(); + + if (phoneNumber.length() != 11) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.phone_number_is_not_valid), false); + return; + } + + ProtoMplGetTopupToken.MplGetTopupToken.Type type = null; + + if (operatorType == null) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.please_select_operator), false); + return; + } + + switch (operatorType) { + case HAMRAH_AVAL: + type = ProtoMplGetTopupToken.MplGetTopupToken.Type.MCI; + break; + case IRANCELL: + switch (fragmentPaymentChargeBinding.fpcSpinnerChargeType.getSelectedItemId() + "") { + case "0": + type = ProtoMplGetTopupToken.MplGetTopupToken.Type.IRANCELL_PREPAID; + break; + case "1": + type = ProtoMplGetTopupToken.MplGetTopupToken.Type.IRANCELL_WOW; + break; + case "2": + type = ProtoMplGetTopupToken.MplGetTopupToken.Type.IRANCELL_WIMAX; + break; + case "3": + type = ProtoMplGetTopupToken.MplGetTopupToken.Type.IRANCELL_POSTPAID; + break; + } + break; + case RITEL: + type = ProtoMplGetTopupToken.MplGetTopupToken.Type.RIGHTEL; + break; + } + + + long price = 0; + + boolean isIranCell = operatorType == OperatorType.IRANCELL; + + switch (fragmentPaymentChargeBinding.fpcSpinnerPrice.getSelectedItemId() + "") { + case "0": + if (isIranCell) { + price = 10900; + } else { + price = 10000; + } + break; + case "1": + if (isIranCell) { + price = 21180; + } else { + price = 20000; + } + break; + case "2": + if (isIranCell) { + price = 54500; + } else { + price = 50000; + } + break; + case "3": + if (isIranCell) { + price = 109000; + } else { + price = 100000; + } + break; + case "4": + if (isIranCell) { + price = 218000; + } else { + price = 200000; + } + break; + } + + G.onMplResult = new OnMplResult() { + @Override + public void onResult(boolean error) { + + if (error) { + observeEnabledPayment.set(true); + } else { + fragmentPaymentChargeBinding.getBackHandler().onBack(); + } + + } + }; + + RequestMplGetTopupToken requestMplGetTopupToken = new RequestMplGetTopupToken(); + requestMplGetTopupToken.mplGetTopupToken(Long.parseLong(phoneNumber), price, type); + + observeEnabledPayment.set(false); + } + + + private static class MySpinnerAdapter extends ArrayAdapter { + + private MySpinnerAdapter(Context context, int resource, List items) { + super(context, resource, items); + } + + // Affects default (closed) state of the spinner + @Override + public View getView(int position, View convertView, ViewGroup parent) { + TextView view = (TextView) super.getView(position, convertView, parent); + view.setTypeface(G.typeface_IRANSansMobile); + + if (position == 0) { + view.setTextColor(G.context.getResources().getColor(R.color.gray)); + } + + return view; + } + + // Affects opened state of the spinner + @Override + public View getDropDownView(int position, View convertView, ViewGroup parent) { + TextView view = (TextView) super.getDropDownView(position, convertView, parent); + view.setTypeface(G.typeface_IRANSansMobile); + view.setTextColor(G.context.getResources().getColor(R.color.gray_4c)); + return view; + } + } + +} diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentPaymentInquiryViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentPaymentInquiryViewModel.java new file mode 100644 index 0000000..36551e8 --- /dev/null +++ b/app/src/main/java/net/iGap/viewmodel/FragmentPaymentInquiryViewModel.java @@ -0,0 +1,346 @@ +package net.iGap.viewmodel; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +import android.content.Context; +import android.databinding.ObservableBoolean; +import android.databinding.ObservableField; +import android.databinding.ObservableInt; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.databinding.FragmentPaymentInquiryBinding; +import net.iGap.helper.HelperError; +import net.iGap.interfaces.OnInquiry; +import net.iGap.proto.ProtoBillInquiryMci; +import net.iGap.proto.ProtoBillInquiryTelecom; +import net.iGap.request.RequestBillInquiryMci; +import net.iGap.request.RequestBillInquiryTelecom; +import net.iGap.request.RequestMplGetBillToken; + +import java.util.HashMap; + +import static net.iGap.fragments.FragmentPaymentBill.addCommasToNumericString; + +public class FragmentPaymentInquiryViewModel { + + public enum OperatorType { + mci, telecome; + } + + public static HashMap MCI = new HashMap() { + { + put("0910", OperatorType.mci); + put("0911", OperatorType.mci); + put("0912", OperatorType.mci); + put("0913", OperatorType.mci); + put("0914", OperatorType.mci); + put("0915", OperatorType.mci); + put("0916", OperatorType.mci); + put("0917", OperatorType.mci); + put("0918", OperatorType.mci); + put("0919", OperatorType.mci); + put("0990", OperatorType.mci); + put("0991", OperatorType.mci); + } + }; + + public ObservableInt observeMci = new ObservableInt(View.GONE); + public ObservableInt observeTelecom = new ObservableInt(View.GONE); + public ObservableInt observeProgress = new ObservableInt(View.GONE); + public ObservableInt observeMidTerm = new ObservableInt(View.VISIBLE); + public ObservableBoolean observeInquiry = new ObservableBoolean(false); + public ObservableBoolean observableLastTermMessage = new ObservableBoolean(false); + public ObservableBoolean observableMidTermMessage = new ObservableBoolean(false); + public ObservableField observeTitleToolbar = new ObservableField<>(""); + + public ObservableField lastTermBillId = new ObservableField<>(""); + public ObservableField lastTermPayId = new ObservableField<>(""); + public ObservableField lastTermAmount = new ObservableField<>(""); + public ObservableField lastTermMessage = new ObservableField<>(""); + + public ObservableField midTermBillId = new ObservableField<>(""); + public ObservableField midTermPayId = new ObservableField<>(""); + public ObservableField midTermAmount = new ObservableField<>(""); + public ObservableField midTermMessage = new ObservableField<>(""); + + public ObservableField observeBackGround = new ObservableField<>(); + + private OperatorType operatorType; + private FragmentPaymentInquiryBinding fragmentPaymentInquiryBinding; + + public FragmentPaymentInquiryViewModel(FragmentPaymentInquiryBinding fragmentPaymentInquiryBinding, OperatorType operatorType) { + this.fragmentPaymentInquiryBinding = fragmentPaymentInquiryBinding; + this.operatorType = operatorType; + + Drawable myIcon = G.context.getResources().getDrawable(R.drawable.oval_green); + myIcon.setColorFilter(Color.parseColor(G.appBarColor), PorterDuff.Mode.SRC_IN); + observeBackGround.set(myIcon); + + switch (operatorType) { + case mci: + observeMci.set(View.VISIBLE); + observeTelecom.set(View.GONE); + observeTitleToolbar.set(G.context.getString(R.string.bills_inquiry_mci)); + fragmentPaymentInquiryBinding.fpiEdtMci.requestFocus(); + + break; + case telecome: + observeMci.set(View.GONE); + observeTelecom.set(View.VISIBLE); + observeTitleToolbar.set(G.context.getString(R.string.bills_inquiry_telecom)); + fragmentPaymentInquiryBinding.fpiEdtTelecomArea.requestFocus(); + break; + } + } + + public void onItemSelectBillType(AdapterView parent, View view, int position, long id) { + switch (position) { + case 0: + observeMci.set(View.VISIBLE); + observeTelecom.set(View.GONE); + operatorType = OperatorType.mci; + fragmentPaymentInquiryBinding.fpiEdtMci.setText(""); + break; + case 1: + fragmentPaymentInquiryBinding.fpiEdtTelecom.setText(""); + fragmentPaymentInquiryBinding.fpiEdtTelecomArea.setText(""); + observeMci.set(View.GONE); + observeTelecom.set(View.VISIBLE); + operatorType = OperatorType.telecome; + break; + } + + + } + + public void onInquiryClick(View view) { + + if (view != null) { + closeKeyboard(view); + } + + + if (observeProgress.get() == View.VISIBLE) { + HelperError.showSnackMessage(G.context.getString(R.string.just_wait_en), false); + return; + } + + if (!G.userLogin) { + HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); + return; + } + + + switch (operatorType) { + case mci: + String phoneMci = fragmentPaymentInquiryBinding.fpiEdtMci.getText().toString(); + + if (phoneMci.length() < 11) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.phone_number_is_not_valid), false); + return; + } + + OperatorType opt = MCI.get(phoneMci.substring(0, 4)); + if (opt == null) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.mci_opreator_check), false); + return; + } + + if (G.userLogin) { + + G.onInquiry = new OnInquiry() { + @Override + public void OnInquiryResult(Object result) { + parsMci(result); + G.onInquiry = null; + observeProgress.set(View.GONE); + } + + @Override + public void OnInquiryError() { + observeProgress.set(View.GONE); + HelperError.showSnackMessage(G.context.getString(R.string.not_answered), false); + } + }; + + + new RequestBillInquiryMci().billInquiryMci(Long.parseLong(phoneMci)); + + observeProgress.set(View.VISIBLE); + + } else { + HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); + } + + break; + case telecome: + + String phoneTelecom = fragmentPaymentInquiryBinding.fpiEdtTelecom.getText().toString(); + String phoneTelecomArea = fragmentPaymentInquiryBinding.fpiEdtTelecomArea.getText().toString(); + + if (phoneTelecom.length() < 8 || phoneTelecomArea.length() < 3) { + HelperError.showSnackMessage(G.context.getResources().getString(R.string.phone_number_is_not_valid), false); + return; + } + + if (G.userLogin) { + + G.onInquiry = new OnInquiry() { + @Override + public void OnInquiryResult(Object result) { + parseTelecom(result); + G.onInquiry = null; + observeProgress.set(View.GONE); + } + + @Override + public void OnInquiryError() { + observeProgress.set(View.GONE); + HelperError.showSnackMessage(G.context.getString(R.string.not_answered), false); + } + }; + + new RequestBillInquiryTelecom().billInquiryTelecom(Integer.parseInt(phoneTelecomArea), Integer.parseInt(phoneTelecom)); + observeProgress.set(View.VISIBLE); + } else { + HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); + } + + break; + } + } + + private void parsMci(Object value) { + + ProtoBillInquiryMci.BillInquiryMciResponse.Builder message = (ProtoBillInquiryMci.BillInquiryMciResponse.Builder) value; + + if (message.getStatus() == 0) { + + observeInquiry.set(true); + + ProtoBillInquiryMci.BillInquiryMciResponse.BillInfo lastTerm = message.getLastTerm(); + ProtoBillInquiryMci.BillInquiryMciResponse.BillInfo midTerm = message.getMidTerm(); + + lastTermBillId.set(lastTerm.getBillId() + ""); + lastTermPayId.set(lastTerm.getPayId() + ""); + lastTermAmount.set(addCommasToNumericString(lastTerm.getAmount() + "")); + lastTermMessage.set(lastTerm.getMessage() + ""); + + midTermBillId.set(midTerm.getBillId() + ""); + midTermPayId.set(midTerm.getPayId() + ""); + midTermAmount.set(addCommasToNumericString(midTerm.getAmount() + "")); + midTermMessage.set(midTerm.getMessage() + ""); + + + if (lastTerm.getStatus() == 0 && lastTerm.getAmount() > 0) { + observableLastTermMessage.set(false); + } else { + observableLastTermMessage.set(true); + } + + if (midTerm.getStatus() == 0 && midTerm.getAmount() > 0) { + observableMidTermMessage.set(false); + } else { + observableMidTermMessage.set(true); + + if (midTerm.getMessage().length() == 0) { + observeMidTerm.set(View.GONE); + } + } + + + } else { + HelperError.showSnackMessage(message.getMessage(), false); + } + + + } + + private void parseTelecom(Object value) { + + ProtoBillInquiryTelecom.BillInquiryTelecomResponse.Builder message = (ProtoBillInquiryTelecom.BillInquiryTelecomResponse.Builder) value; + + if (message.getStatus() == 0) { + + observeInquiry.set(true); + + ProtoBillInquiryTelecom.BillInquiryTelecomResponse.BillInfo lastTerm = message.getLastTerm(); + ProtoBillInquiryTelecom.BillInquiryTelecomResponse.BillInfo midTerm = message.getMidTerm(); + + lastTermBillId.set(lastTerm.getBillId() + ""); + lastTermPayId.set(lastTerm.getPayId() + ""); + lastTermAmount.set(addCommasToNumericString(lastTerm.getAmount() + "")); + + midTermBillId.set(midTerm.getBillId() + ""); + midTermPayId.set(midTerm.getPayId() + ""); + midTermAmount.set(addCommasToNumericString(midTerm.getAmount() + "")); + + + if (lastTerm.getAmount() > 0) { + observableLastTermMessage.set(false); + } else { + observableLastTermMessage.set(true); + } + + if (midTerm.getAmount() > 0) { + observableMidTermMessage.set(false); + } else { + observableMidTermMessage.set(true); + observeMidTerm.set(View.GONE); + } + + } else { + HelperError.showSnackMessage(message.getMessage(), false); + } + + } + + private void closeKeyboard(final View v) { + G.handler.post(new Runnable() { + @Override + public void run() { + InputMethodManager imm = (InputMethodManager) G.context.getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.hideSoftInputFromWindow(v.getWindowToken(), 0); + } + } + }); + } + + public void onLastTermPayment(View v) { + + if (!G.userLogin) { + HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); + return; + } + + RequestMplGetBillToken requestMplGetBillToken = new RequestMplGetBillToken(); + requestMplGetBillToken.mplGetBillToken(Long.parseLong(lastTermBillId.get()), Long.parseLong(lastTermPayId.get())); + fragmentPaymentInquiryBinding.getBackHandler().onBack(); + } + + public void onMidTermPayment(View v) { + + if (!G.userLogin) { + HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); + return; + } + RequestMplGetBillToken requestMplGetBillToken = new RequestMplGetBillToken(); + requestMplGetBillToken.mplGetBillToken(Long.parseLong(midTermBillId.get()), Long.parseLong(midTermPayId.get())); + fragmentPaymentInquiryBinding.getBackHandler().onBack(); + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentPaymentViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentPaymentViewModel.java new file mode 100644 index 0000000..a4d6937 --- /dev/null +++ b/app/src/main/java/net/iGap/viewmodel/FragmentPaymentViewModel.java @@ -0,0 +1,58 @@ +package net.iGap.viewmodel; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. +*/ + +import android.databinding.ObservableField; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.view.View; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.fragments.FragmentPaymentBill; +import net.iGap.fragments.FragmentPaymentCharge; +import net.iGap.fragments.FragmentPaymentInquiry; +import net.iGap.helper.HelperFragment; + + +public class FragmentPaymentViewModel { + + public ObservableField observeBackGround = new ObservableField<>(); + + public FragmentPaymentViewModel(Bundle arguments) { + + Drawable myIcon = G.context.getResources().getDrawable(R.drawable.oval_green); + myIcon.setColorFilter(Color.parseColor(G.appBarColor), PorterDuff.Mode.SRC_IN); + observeBackGround.set(myIcon); + } + + public void onClickCharge(View v) { + new HelperFragment(FragmentPaymentCharge.newInstance()).setReplace(false).load(); + } + + public void onClickBill(View v) { + new HelperFragment(FragmentPaymentBill.newInstance(R.string.pay_bills)).setReplace(false).load(); + } + + public void onClickBillTraffic(View v) { + new HelperFragment(FragmentPaymentBill.newInstance(R.string.pay_bills_crime)).setReplace(false).load(); + } + + public void onClickInquiryMci(View v) { + new HelperFragment(FragmentPaymentInquiry.newInstance(FragmentPaymentInquiryViewModel.OperatorType.mci, null)).setReplace(false).load(); + } + + public void onClickInquiryTelecom(View v) { + new HelperFragment(FragmentPaymentInquiry.newInstance(FragmentPaymentInquiryViewModel.OperatorType.telecome, null)).setReplace(false).load(); + } + +} diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentRegisterViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentRegisterViewModel.java index 5ba86fa..f7adb8b 100644 --- a/app/src/main/java/net/iGap/viewmodel/FragmentRegisterViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/FragmentRegisterViewModel.java @@ -7,7 +7,7 @@ * iGap Messenger | Free, Fast and Secure instant messaging application * The idea of the RooyeKhat Media Company - www.RooyeKhat.co * All rights reserved. -*/ + */ import android.app.Activity; import android.app.Dialog; @@ -153,10 +153,6 @@ public class FragmentRegisterViewModel implements OnSecurityCheckPassword, OnRec public ObservableInt txtVerifyServerColor = new ObservableInt(G.context.getResources().getColor(R.color.rg_text_verify)); public ObservableInt btnStartColor = new ObservableInt(G.context.getResources().getColor(R.color.rg_whit_background)); public ObservableInt btnStartBackgroundColor = new ObservableInt(Color.parseColor(G.appBarColor)); - public ObservableInt txtVerifyConnectAppearance = new ObservableInt(); - public ObservableInt txtVerifyServerAppearance = new ObservableInt(); - public ObservableInt txtVerifyKeyAppearance = new ObservableInt(); - public ObservableInt txtVerifySmsAppearance = new ObservableInt(); public ObservableBoolean edtCodeNumberEnable = new ObservableBoolean(false); public ObservableBoolean btnChoseCountryEnable = new ObservableBoolean(true); public ObservableBoolean edtPhoneNumberEnable = new ObservableBoolean(true); @@ -866,10 +862,8 @@ public void run() { prgVerifyConnectVisibility.set(View.GONE); txtIconVerifyConnectVisibility.set(View.VISIBLE); imgVerifySmsVisibility.set(View.GONE); - //txtVerifyConnectAppearance.set(R.style.RedHUGEText); txtVerifyConnectColor.set(G.context.getResources().getColor(R.color.rg_text_verify)); prgVerifySmsVisibility.set(View.VISIBLE); - //txtVerifySmsAppearance.set(R.style.RedHUGEText); } }); @@ -1020,7 +1014,6 @@ private void userVerify(final String userName, final String verificationCode) { if (G.socketConnection) { prgVerifyKeyVisibility.set(View.VISIBLE); - //txtVerifyKeyAppearance.set(R.style.RedHUGEText); userVerifyResponse(verificationCode); @@ -1042,7 +1035,6 @@ private void userVerify(final String userName, final String verificationCode) { // return step one prgVerifyConnectVisibility.set(View.VISIBLE); txtIconVerifyConnectVisibility.set(View.GONE); - txtVerifyConnectAppearance.set(Typeface.NORMAL); // clear step two prgVerifySmsVisibility.set(View.GONE); imgVerifySmsVisibility.set(View.INVISIBLE); @@ -1095,6 +1087,8 @@ public void run() { }); } else if (majorCode == 102 && minorCode == 2) { //empty + } else if (majorCode == 10) { + if (time != 0) dialogWaitTimeVerifyPassword(time); } else if (majorCode == 103) { //empty } else if (majorCode == 104) { @@ -1199,7 +1193,6 @@ public void run() { private void userLogin(final String token) { prgVerifyServerVisibility.set(View.VISIBLE); - //txtVerifyServerAppearance.set(R.style.RedHUGEText); G.onUserLogin = new OnUserLogin() { @Override diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentSettingViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentSettingViewModel.java index ace1821..980c74d 100644 --- a/app/src/main/java/net/iGap/viewmodel/FragmentSettingViewModel.java +++ b/app/src/main/java/net/iGap/viewmodel/FragmentSettingViewModel.java @@ -16,7 +16,6 @@ import android.content.pm.PackageManager; import android.databinding.ObservableField; import android.graphics.Color; -import android.graphics.drawable.GradientDrawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -40,11 +39,7 @@ import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.GravityEnum; import com.afollestad.materialdialogs.MaterialDialog; -import com.larswerkman.holocolorpicker.ColorPicker; -import com.larswerkman.holocolorpicker.OpacityBar; -import com.larswerkman.holocolorpicker.SVBar; -import net.iGap.Config; import net.iGap.G; import net.iGap.R; import net.iGap.activities.ActivityManageSpace; @@ -52,7 +47,6 @@ import net.iGap.fragments.FragmentBio; import net.iGap.fragments.FragmentCall; import net.iGap.fragments.FragmentChatBackground; -import net.iGap.fragments.FragmentDarkTheme; import net.iGap.fragments.FragmentData; import net.iGap.fragments.FragmentDeleteAccount; import net.iGap.fragments.FragmentLanguage; @@ -61,6 +55,7 @@ import net.iGap.fragments.FragmentPrivacyAndSecurity; import net.iGap.fragments.FragmentSetting; import net.iGap.fragments.FragmentShowAvatars; +import net.iGap.fragments.FragmentThemColor; import net.iGap.helper.HelperCalander; import net.iGap.helper.HelperError; import net.iGap.helper.HelperFragment; @@ -104,13 +99,8 @@ import io.realm.RealmModel; import static android.content.Context.MODE_PRIVATE; -import static net.iGap.G.appBarColor; -import static net.iGap.G.attachmentColor; import static net.iGap.G.context; -import static net.iGap.G.headerTextColor; -import static net.iGap.G.notificationColor; import static net.iGap.G.onRefreshActivity; -import static net.iGap.G.toggleButtonColor; import static net.iGap.R.string.log_out; public class FragmentSettingViewModel { @@ -165,6 +155,7 @@ public class FragmentSettingViewModel { public ObservableField isTime = new ObservableField<>(); public ObservableField isCameraButtonSheet = new ObservableField<>(true); public ObservableField isAutoThemeDark = new ObservableField<>(View.GONE); + public ObservableField isGoneLayoutColor = new ObservableField<>(View.VISIBLE); private static SharedPreferences sharedPreferences; @@ -432,7 +423,10 @@ public void onClickNickname(View view) { layoutNickname.addView(inputLastName, lastNameLayoutParams); final MaterialDialog dialog = - new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_nickname)).positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)).customView(layoutNickname, true).widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + new MaterialDialog.Builder(G.fragmentActivity) + .title(G.fragmentActivity.getResources().getString(R.string.st_nickname)) + .positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok)).customView(layoutNickname, true) + .widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); final View positive = dialog.getActionButton(DialogAction.POSITIVE); positive.setEnabled(false); @@ -486,7 +480,7 @@ public void afterTextChanged(Editable editable) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewFirstName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } @@ -497,7 +491,7 @@ public void onFocusChange(View view, boolean b) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewLastName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } @@ -595,7 +589,7 @@ public void onClickUserName(View view) { layoutUserName.addView(inputUserName, layoutParams); final MaterialDialog dialog = - new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_username)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_username)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutUserName, true).widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); final View positive = dialog.getActionButton(DialogAction.POSITIVE); positive.setEnabled(false); @@ -714,7 +708,7 @@ public void run() { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewUserName.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } @@ -821,7 +815,7 @@ public void onClickSetEmail(View view) { layoutEmail.addView(inputEmail, layoutParams); final MaterialDialog dialog = - new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_email)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutEmail, true).widgetColor(G.context.getResources().getColor(R.color.toolbar_background)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); + new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.st_email)).positiveText(G.fragmentActivity.getResources().getString(R.string.save)).customView(layoutEmail, true).widgetColor(Color.parseColor(G.appBarColor)).negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel)).build(); final View positive = dialog.getActionButton(DialogAction.POSITIVE); positive.setEnabled(false); @@ -864,7 +858,7 @@ public void onClick(View view) { @Override public void onFocusChange(View view, boolean b) { if (b) { - viewEmail.setBackgroundColor(G.context.getResources().getColor(R.color.toolbar_background)); + viewEmail.setBackgroundColor(Color.parseColor(G.appBarColor)); } else { viewEmail.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text)); } @@ -1116,108 +1110,9 @@ public void onCheckedChangedSendEnter(boolean isChecked) { } } - public void onClickThemeDark(View view) { - isThemeDark.set(!isThemeDark.get()); - SharedPreferences.Editor editor = sharedPreferences.edit(); - if (isThemeDark.get()) { - isAutoThemeDark.set(View.VISIBLE); - setDarkTheme(editor); - } else { - isAutoThemeDark.set(View.GONE); - setLightTheme(editor); - } - } - -// public boolean isDarkTheme() { -// return isThemeDark.get(); -// } - - public void onClickAutoTimeDarkTheme(View v) { - new HelperFragment(FragmentDarkTheme.newInstance()).setReplace(false).load(); - } - - public static void setLightTheme(SharedPreferences.Editor editor) { - G.isDarkTheme = false; - editor.putBoolean(SHP_SETTING.KEY_THEME_DARK, false); - editor.putBoolean(SHP_SETTING.KEY_DISABLE_TIME_DARK_THEME, true); - editor.apply(); - notificationColorClick(Color.parseColor(Config.default_notificationColor), false); - headerColorClick(Color.parseColor(Config.default_headerTextColor), false); - toggleBottomClick(Color.parseColor(Config.default_toggleButtonColor)); - sendAndAttachColorClick(Color.parseColor(Config.default_attachmentColor)); - appBarColorClick(Color.parseColor(Config.default_appBarColor)); - progressColorClick(Color.parseColor(Config.default_appBarColor), false); - menuBackgroundClick(Color.parseColor(Config.default_appBarColor), false); - Config.lightThemeColor(); - } - - public static void setDarkTheme(SharedPreferences.Editor editor) { - G.isDarkTheme = true; - - editor.putBoolean(SHP_SETTING.KEY_THEME_DARK, true); - editor.putString(SHP_SETTING.KEY_APP_BAR_COLOR, Config.default_dark_appBarColor); - editor.putString(SHP_SETTING.KEY_NOTIFICATION_COLOR, Config.default_dark_notificationColor); - editor.putString(SHP_SETTING.KEY_TOGGLE_BOTTON_COLOR, Config.default_dark_toggleButtonColor); - editor.putString(SHP_SETTING.KEY_SEND_AND_ATTACH_ICON_COLOR, Config.default_dark_attachmentColor); - editor.putString(SHP_SETTING.KEY_FONT_HEADER_COLOR, Config.default_dark_headerTextColor); - editor.putString(SHP_SETTING.KEY_PROGRES_COLOR, Config.default_dark_progressColor); - editor.putString(SHP_SETTING.KEY_MENU_BACKGROUND_COLOR, Config.default_dark_menuBackgroundColor); - editor.apply(); - - appBarColor = Config.default_dark_appBarColor; - notificationColor = Config.default_dark_notificationColor; - toggleButtonColor = Config.default_dark_toggleButtonColor; - attachmentColor = Config.default_dark_attachmentColor; - headerTextColor = Config.default_dark_headerTextColor; - G.progressColor = Config.default_dark_progressColor; - - Config.darkThemeColor(); - - G.isUpdateNotificaionColorMain = true; - G.isUpdateNotificaionColorChannel = true; - G.isUpdateNotificaionColorGroup = true; - G.isUpdateNotificaionColorChat = true; - G.fragmentActivity.recreate(); - - if (G.onRefreshActivity != null) { - G.isRestartActivity = true; - G.onRefreshActivity.refresh(""); - } - } - - public void onCheckedChangedThemeDark(boolean isChecked) { - - } - - public void onClickTitleBarColor(View view) { - showSelectAppColorDialog(R.string.app_theme); - } - - public void onClickNotificationColor(View view) { - showSelectAppColorDialog(R.string.app_notif_color); - } - - public void onClickToggleBottonColor(View view) { - showSelectAppColorDialog(R.string.toggle_botton_color); - } - - public void onClickSendAndAttachColor(View view) { - showSelectAppColorDialog(R.string.send_and_attach_botton_color); - } - - public void onClickDefaultHeaderFontColor(View view) { - - showSelectAppColorDialog(R.string.default_header_font_color); - } - - public void onClickDefaultProgressColor(View view) { - showSelectAppColorDialog(R.string.default_progress_color); - } - - public void onClickSetColorToDefault(View view) { - - showSetDefaultColorDialog(); + public void onClickThemeColor(View v) { + new HelperFragment(new FragmentThemColor()).setReplace(false).load(); } public void onClickAutoDownloadData(View view) { @@ -1619,6 +1514,13 @@ public void dataName(String type) { isAutoThemeDark.set(View.GONE); } + if (G.isDarkTheme) { + isGoneLayoutColor.set(View.GONE); + } else { + isGoneLayoutColor.set(View.VISIBLE); + } + + int checkedAutoGif = sharedPreferences.getInt(SHP_SETTING.KEY_AUTOPLAY_GIFS, SHP_SETTING.Defaults.KEY_AUTOPLAY_GIFS); isAutoGif.set(getBoolean(checkedAutoGif)); @@ -1629,7 +1531,7 @@ public void dataName(String type) { int checkedEnableTrim = sharedPreferences.getInt(SHP_SETTING.KEY_TRIM, 1); isTrim.set(getBoolean(checkedEnableTrim)); - int checkedEnableDefaultPlayer = sharedPreferences.getInt(SHP_SETTING.KEY_DEFAULT_PLAYER, 0); + int checkedEnableDefaultPlayer = sharedPreferences.getInt(SHP_SETTING.KEY_DEFAULT_PLAYER, 1); isDefaultPlayer.set(getBoolean(checkedEnableDefaultPlayer)); callbackVersionApp.set(G.fragmentActivity.getResources().getString(R.string.iGap_version) + " " + getAppVersion()); @@ -1785,249 +1687,39 @@ private boolean getBoolean(int num) { return true; } - private void showSelectAppColorDialog(final int title) { - - boolean wrapInScrollView = true; - - String titleMessage = G.fragmentActivity.getResources().getString(title); - - final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).customView(R.layout.stns_popup_colorpicer, wrapInScrollView).positiveText(G.fragmentActivity.getResources().getString(R.string.set)).negativeText(G.fragmentActivity.getResources().getString(R.string.DISCARD)).title(titleMessage).onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - - } - }).onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - - } - }).build(); - - View view1 = dialog.getCustomView(); - assert view1 != null; - final ColorPicker picker = (ColorPicker) view1.findViewById(R.id.picker); - SVBar svBar = (SVBar) view1.findViewById(R.id.svbar); - OpacityBar opacityBar = (OpacityBar) view1.findViewById(R.id.opacitybar); - picker.addSVBar(svBar); - picker.addOpacityBar(opacityBar); - - dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - - dialog.dismiss(); - - try { - - String _strColor = "#" + Integer.toHexString(picker.getColor()); - int _color = Color.parseColor(_strColor); // if can not parae selected color do not set selected color - - switch (title) { - - case R.string.app_theme: - appBarColorClick(picker.getColor()); - break; - case R.string.app_notif_color: - notificationColorClick(picker.getColor(), true); - break; - case R.string.toggle_botton_color: - toggleBottomClick(picker.getColor()); - break; - case R.string.send_and_attach_botton_color: - sendAndAttachColorClick(picker.getColor()); - break; - case R.string.default_header_font_color: - headerColorClick(picker.getColor(), true); - break; - case R.string.default_progress_color: - progressColorClick(picker.getColor(), true); - break; - - } - } catch (IllegalArgumentException e) { - - new MaterialDialog.Builder(G.fragmentActivity).title(R.string.selected_color_can_not_set_on_yout_device).cancelable(true).show(); - } - } - }); - - dialog.show(); - } - - private void showSetDefaultColorDialog() { - new MaterialDialog.Builder(G.fragmentActivity).title(R.string.set_color_to_default).content(R.string.color_default).positiveText(R.string.st_dialog_reset_all_notification_yes).onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - notificationColorClick(Color.parseColor(Config.default_notificationColor), false); - headerColorClick(Color.parseColor(Config.default_headerTextColor), false); - toggleBottomClick(Color.parseColor(Config.default_toggleButtonColor)); - sendAndAttachColorClick(Color.parseColor(Config.default_attachmentColor)); - appBarColorClick(Color.parseColor(Config.default_appBarColor)); - progressColorClick(Color.parseColor(Config.default_appBarColor), false); - } - }).negativeText(R.string.st_dialog_reset_all_notification_no).onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - - } - }).show(); - } - - public static void appBarColorClick(int color) { - - SharedPreferences.Editor editor; - if (sharedPreferences == null) { - SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - editor = sharedPreferences.edit(); - } else { - editor = sharedPreferences.edit(); - } - if (fragmentSettingBinding != null) { - GradientDrawable bgShape = (GradientDrawable) fragmentSettingBinding.asnImgTitleBarColor.getBackground(); - bgShape.setColor(color); - } - - G.appBarColor = "#" + Integer.toHexString(color); - editor.putString(SHP_SETTING.KEY_APP_BAR_COLOR, G.appBarColor); - editor.apply(); - - // G.fragmentActivity.recreate(); - if (G.onRefreshActivity != null) { - G.isRestartActivity = true; - G.onRefreshActivity.refresh(""); - } - } - - public static void notificationColorClick(int color, boolean updateUi) { - SharedPreferences.Editor editor; - if (sharedPreferences == null) { - SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - editor = sharedPreferences.edit(); - } else { - editor = sharedPreferences.edit(); - } - if (fragmentSettingBinding != null) { - GradientDrawable bgShape = (GradientDrawable) fragmentSettingBinding.asnImgNotificationColor.getBackground(); - bgShape.setColor(color); - } - G.notificationColor = "#" + Integer.toHexString(color); - editor.putString(SHP_SETTING.KEY_NOTIFICATION_COLOR, G.notificationColor); - editor.apply(); - - G.isUpdateNotificaionColorMain = true; - G.isUpdateNotificaionColorChannel = true; - G.isUpdateNotificaionColorGroup = true; - G.isUpdateNotificaionColorChat = true; - - //if (updateUi && G.onRefreshActivity != null) { - // G.onRefreshActivity.refresh(""); - //} - } - - public static void progressColorClick(int color, boolean updateUi) { - - SharedPreferences.Editor editor; - if (sharedPreferences == null) { - SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - editor = sharedPreferences.edit(); - } else { - editor = sharedPreferences.edit(); - } - - if (fragmentSettingBinding != null) { - GradientDrawable bgShape = (GradientDrawable) fragmentSettingBinding.asnImgDefaultProgressColor.getBackground(); - bgShape.setColor(color); - } - - G.progressColor = "#" + Integer.toHexString(color); - editor.putString(SHP_SETTING.KEY_PROGRES_COLOR, G.progressColor); - editor.apply(); - - //if (updateUi && G.onRefreshActivity != null) { - // G.onRefreshActivity.refresh(""); - //} - } - - public static void menuBackgroundClick(int color, boolean updateUi) { - - SharedPreferences.Editor editor; - if (sharedPreferences == null) { - SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - editor = sharedPreferences.edit(); - } else { - editor = sharedPreferences.edit(); - } - if (fragmentSettingBinding != null) { - GradientDrawable bgShape = (GradientDrawable) fragmentSettingBinding.asnImgDefaultProgressColor.getBackground(); - bgShape.setColor(color); - } - - G.progressColor = "#" + Integer.toHexString(color); - editor.putString(SHP_SETTING.KEY_PROGRES_COLOR, G.progressColor); - editor.apply(); - - } - - public static void toggleBottomClick(int color) { - SharedPreferences.Editor editor; - if (sharedPreferences == null) { - SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - editor = sharedPreferences.edit(); - } else { - editor = sharedPreferences.edit(); - } - - if (fragmentSettingBinding != null) { - GradientDrawable bgShape = (GradientDrawable) fragmentSettingBinding.asnImgToggleBottonColor.getBackground(); - bgShape.setColor(color); - } - G.toggleButtonColor = "#" + Integer.toHexString(color); - editor.putString(SHP_SETTING.KEY_TOGGLE_BOTTON_COLOR, G.toggleButtonColor); - editor.apply(); - } - - public static void headerColorClick(int color, boolean updateUi) { - SharedPreferences.Editor editor; - if (sharedPreferences == null) { - SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - editor = sharedPreferences.edit(); - } else { - editor = sharedPreferences.edit(); - } - - if (fragmentSettingBinding != null) { - GradientDrawable bgShape = (GradientDrawable) fragmentSettingBinding.asnImgDefaultHeaderFontColor.getBackground(); - bgShape.setColor(color); - } - - - G.headerTextColor = "#" + Integer.toHexString(color); - editor.putString(SHP_SETTING.KEY_FONT_HEADER_COLOR, G.headerTextColor); - editor.apply(); - - if (updateUi) { - G.isRestartActivity = true; - G.fragmentActivity.recreate(); - } - } - - public static void sendAndAttachColorClick(int color) { - SharedPreferences.Editor editor; - if (sharedPreferences == null) { - SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); - editor = sharedPreferences.edit(); - } else { - editor = sharedPreferences.edit(); - } - if (fragmentSettingBinding != null) { - GradientDrawable bgShape = (GradientDrawable) fragmentSettingBinding.asnImgSendAndAttachColor.getBackground(); - bgShape.setColor(color); - } - G.attachmentColor = "#" + Integer.toHexString(color); - editor.putString(SHP_SETTING.KEY_SEND_AND_ATTACH_ICON_COLOR, G.attachmentColor); - editor.apply(); - } +// private void showSetDefaultColorDialog() { +// +// new MaterialDialog.Builder(G.fragmentActivity).title(R.string.set_color_to_default).content(R.string.color_default).positiveText(R.string.st_dialog_reset_all_notification_yes).onPositive(new MaterialDialog.SingleButtonCallback() { +// @Override +// public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { +// +// SharedPreferences.Editor editor; +// if (sharedPreferences == null) { +// SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); +// editor = sharedPreferences.edit(); +// } else { +// editor = sharedPreferences.edit(); +// +// } +// editor.putInt(SHP_SETTING.KEY_THEME_COLOR, Config.DEFAULT); +// editor.apply(); +// +// Config.setThemeColor(); +// +// if (G.onRefreshActivity != null) { +// G.isRestartActivity = true; +// G.onRefreshActivity.refresh(""); +// } +// +// } +// }).negativeText(R.string.st_dialog_reset_all_notification_no).onNegative(new MaterialDialog.SingleButtonCallback() { +// @Override +// public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { +// +// } +// }).show(); +// } private String getAppVersion() { diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentThemColorCustomViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentThemColorCustomViewModel.java new file mode 100644 index 0000000..f0d5742 --- /dev/null +++ b/app/src/main/java/net/iGap/viewmodel/FragmentThemColorCustomViewModel.java @@ -0,0 +1,298 @@ +package net.iGap.viewmodel; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +import android.content.SharedPreferences; +import android.graphics.Color; +import android.graphics.drawable.GradientDrawable; +import android.support.annotation.NonNull; +import android.view.View; + +import com.afollestad.materialdialogs.DialogAction; +import com.afollestad.materialdialogs.MaterialDialog; +import com.larswerkman.holocolorpicker.ColorPicker; +import com.larswerkman.holocolorpicker.OpacityBar; +import com.larswerkman.holocolorpicker.SVBar; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.Theme; +import net.iGap.databinding.FragmentThemColorCustomBinding; +import net.iGap.fragments.FragmentThemColorCustom; +import net.iGap.module.SHP_SETTING; + +import static android.content.Context.MODE_PRIVATE; +import static net.iGap.viewmodel.FragmentThemColorViewModel.resetApp; + + +public class FragmentThemColorCustomViewModel { + + private SharedPreferences sharedPreferences; + private FragmentThemColorCustom fragmentThemColorCustom; + private FragmentThemColorCustomBinding fragmentThemColorCustomBinding; + + + public FragmentThemColorCustomViewModel(FragmentThemColorCustom fragmentThemColorCustom, FragmentThemColorCustomBinding fragmentThemColorCustomBinding) { + this.fragmentThemColorCustom = fragmentThemColorCustom; + this.fragmentThemColorCustomBinding = fragmentThemColorCustomBinding; + getInfo(); + } + + //=============================================================================== + //================================Event Listeners================================ + //=============================================================================== + + + public void onClickSetTheme(View view) { + SharedPreferences.Editor editor; + if (sharedPreferences == null) { + SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); + editor = sharedPreferences.edit(); + } else { + editor = sharedPreferences.edit(); + } + editor.putInt(SHP_SETTING.KEY_THEME_COLOR, Theme.CUSTOM); + editor.putBoolean(SHP_SETTING.KEY_THEME_DARK, false); + editor.apply(); + + Theme.setThemeColor(); + resetApp(); + + } + + public void onClickTitleBarColor(View view) { + showSelectAppColorDialog(R.string.app_theme); + } + + public void onClickNotificationColor(View view) { + showSelectAppColorDialog(R.string.app_notif_color); + } + + public void onClickToggleBottonColor(View view) { + showSelectAppColorDialog(R.string.toggle_botton_color); + } + + public void onClickSendAndAttachColor(View view) { + showSelectAppColorDialog(R.string.send_and_attach_botton_color); + } + + public void onClickDefaultHeaderFontColor(View view) { + showSelectAppColorDialog(R.string.default_header_font_color); + } + + public void onClickDefaultProgressColor(View view) { + showSelectAppColorDialog(R.string.default_progress_color); + } + + + private void showSelectAppColorDialog(final int title) { + + boolean wrapInScrollView = true; + + String titleMessage = G.fragmentActivity.getResources().getString(title); + + final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).customView(R.layout.stns_popup_colorpicer, wrapInScrollView).positiveText(G.fragmentActivity.getResources().getString(R.string.set)).negativeText(G.fragmentActivity.getResources().getString(R.string.DISCARD)).title(titleMessage).onNegative(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + + } + }).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + + } + }).build(); + + View view1 = dialog.getCustomView(); + assert view1 != null; + final ColorPicker picker = (ColorPicker) view1.findViewById(R.id.picker); + SVBar svBar = (SVBar) view1.findViewById(R.id.svbar); + OpacityBar opacityBar = (OpacityBar) view1.findViewById(R.id.opacitybar); + picker.addSVBar(svBar); + picker.addOpacityBar(opacityBar); + + dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + dialog.dismiss(); + + try { + + String _strColor = "#" + Integer.toHexString(picker.getColor()); + int _color = Color.parseColor(_strColor); // if can not parae selected color do not set selected color + + SharedPreferences.Editor editor; + if (sharedPreferences == null) { + SharedPreferences sharedPreferences = G.fragmentActivity.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); + editor = sharedPreferences.edit(); + } else { + editor = sharedPreferences.edit(); + } + + switch (title) { + + case R.string.app_theme: + + G.appBarColor = "#" + Integer.toHexString(picker.getColor()); + editor.putString(SHP_SETTING.KEY_APP_BAR_COLOR, G.appBarColor); + editor.apply(); + appBarColorClick(0); + + + break; + case R.string.app_notif_color: + + G.notificationColor = "#" + Integer.toHexString(picker.getColor()); + editor.putString(SHP_SETTING.KEY_NOTIFICATION_COLOR, G.notificationColor); + editor.apply(); + notificationColorClick(0, true); + + break; + case R.string.toggle_botton_color: + + G.toggleButtonColor = "#" + Integer.toHexString(picker.getColor()); + editor.putString(SHP_SETTING.KEY_TOGGLE_BOTTON_COLOR, G.toggleButtonColor); + editor.apply(); + toggleBottomClick(0); + + break; + case R.string.send_and_attach_botton_color: + + G.attachmentColor = "#" + Integer.toHexString(picker.getColor()); + editor.putString(SHP_SETTING.KEY_SEND_AND_ATTACH_ICON_COLOR, G.attachmentColor); + editor.apply(); + sendAndAttachColorClick(0); + break; + case R.string.default_header_font_color: + + G.headerTextColor = "#" + Integer.toHexString(picker.getColor()); + editor.putString(SHP_SETTING.KEY_FONT_HEADER_COLOR, G.headerTextColor); + editor.apply(); + headerColorClick(0, true); + + break; + case R.string.default_progress_color: + + G.progressColor = "#" + Integer.toHexString(picker.getColor()); + editor.putString(SHP_SETTING.KEY_PROGRES_COLOR, G.progressColor); + editor.apply(); + progressColorClick(0, true); + break; + + + } + } catch (IllegalArgumentException e) { + + new MaterialDialog.Builder(G.fragmentActivity).title(R.string.selected_color_can_not_set_on_yout_device).cancelable(true).show(); + } + } + }); + + dialog.show(); + } + + + private void getInfo() { + sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); + + String appBarColor = sharedPreferences.getString(SHP_SETTING.KEY_APP_BAR_COLOR, Theme.default_appBarColor); + String notificationColor = sharedPreferences.getString(SHP_SETTING.KEY_NOTIFICATION_COLOR, Theme.default_notificationColor); + String toggleButtonColor = sharedPreferences.getString(SHP_SETTING.KEY_TOGGLE_BOTTON_COLOR, Theme.default_toggleButtonColor); + String attachmentColor = sharedPreferences.getString(SHP_SETTING.KEY_SEND_AND_ATTACH_ICON_COLOR, Theme.default_attachmentColor); + String headerTextColor = sharedPreferences.getString(SHP_SETTING.KEY_FONT_HEADER_COLOR, Theme.default_headerTextColor); + String progressColor = sharedPreferences.getString(SHP_SETTING.KEY_PROGRES_COLOR, Theme.default_progressColor); + + //*********************** + GradientDrawable bgShape = (GradientDrawable) fragmentThemColorCustomBinding.asnImgTitleBarColor.getBackground(); + bgShape.setColor(Color.parseColor(appBarColor)); + + //*********************** + + GradientDrawable bgShapeNotification = (GradientDrawable) fragmentThemColorCustomBinding.asnImgNotificationColor.getBackground(); + bgShapeNotification.setColor(Color.parseColor(notificationColor)); + + //*********************** + + GradientDrawable bgShapeToggleBottomColor = (GradientDrawable) fragmentThemColorCustomBinding.asnImgToggleBottonColor.getBackground(); + bgShapeToggleBottomColor.setColor(Color.parseColor(toggleButtonColor)); + + /* + page for show all image user + */ + GradientDrawable bgShapeSendAndAttachColor = (GradientDrawable) fragmentThemColorCustomBinding.asnImgSendAndAttachColor.getBackground(); + bgShapeSendAndAttachColor.setColor(Color.parseColor(attachmentColor)); + + + //*********************** + + GradientDrawable bgShapeHeaderTextColor = (GradientDrawable) fragmentThemColorCustomBinding.asnImgDefaultHeaderFontColor.getBackground(); + bgShapeHeaderTextColor.setColor(Color.parseColor(headerTextColor)); + + //*********************** + + GradientDrawable bgShapeProgressColor = (GradientDrawable) fragmentThemColorCustomBinding.asnImgDefaultProgressColor.getBackground(); + bgShapeProgressColor.setColor(Color.parseColor(progressColor)); + + + } + + public void appBarColorClick(int color) { + + if (fragmentThemColorCustomBinding != null) { + GradientDrawable bgShape = (GradientDrawable) fragmentThemColorCustomBinding.asnImgTitleBarColor.getBackground(); + bgShape.setColor(Color.parseColor(G.appBarColor)); + } + } + + public void notificationColorClick(int color, boolean updateUi) { + + if (fragmentThemColorCustomBinding != null) { + GradientDrawable bgShape = (GradientDrawable) fragmentThemColorCustomBinding.asnImgNotificationColor.getBackground(); + bgShape.setColor(Color.parseColor(G.notificationColor)); + } + + } + + public void progressColorClick(int color, boolean updateUi) { + + + if (fragmentThemColorCustomBinding != null) { + GradientDrawable bgShape = (GradientDrawable) fragmentThemColorCustomBinding.asnImgDefaultProgressColor.getBackground(); + bgShape.setColor(Color.parseColor(G.progressColor)); + } + } + + + public void toggleBottomClick(int color) { + + if (fragmentThemColorCustomBinding != null) { + GradientDrawable bgShape = (GradientDrawable) fragmentThemColorCustomBinding.asnImgToggleBottonColor.getBackground(); + bgShape.setColor(Color.parseColor(G.toggleButtonColor)); + } + } + + public void headerColorClick(int color, boolean updateUi) { + + if (fragmentThemColorCustomBinding != null) { + GradientDrawable bgShape = (GradientDrawable) fragmentThemColorCustomBinding.asnImgDefaultHeaderFontColor.getBackground(); + bgShape.setColor(Color.parseColor(G.headerTextColor)); + } + } + + public void sendAndAttachColorClick(int color) { + + if (fragmentThemColorCustomBinding != null) { + GradientDrawable bgShape = (GradientDrawable) fragmentThemColorCustomBinding.asnImgSendAndAttachColor.getBackground(); + bgShape.setColor(Color.parseColor(G.attachmentColor)); + } + + } +} diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentThemColorViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentThemColorViewModel.java new file mode 100644 index 0000000..93b67c9 --- /dev/null +++ b/app/src/main/java/net/iGap/viewmodel/FragmentThemColorViewModel.java @@ -0,0 +1,408 @@ +package net.iGap.viewmodel; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ + +import android.content.SharedPreferences; +import android.graphics.Color; +import android.graphics.drawable.GradientDrawable; +import android.view.View; + +import com.afollestad.materialdialogs.DialogAction; +import com.afollestad.materialdialogs.MaterialDialog; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.Theme; +import net.iGap.databinding.FragmentThemColorBinding; +import net.iGap.fragments.FragmentDarkTheme; +import net.iGap.fragments.FragmentThemColor; +import net.iGap.fragments.FragmentThemColorCustom; +import net.iGap.helper.HelperFragment; +import net.iGap.module.SHP_SETTING; + +import static android.content.Context.MODE_PRIVATE; + +public class FragmentThemColorViewModel { + + private SharedPreferences sharedPreferences; + private FragmentThemColor fragmentThemColor; + private FragmentThemColorBinding fragmentThemColorBinding; + + + public FragmentThemColorViewModel(FragmentThemColor fragmentThemColor, FragmentThemColorBinding fragmentThemColorBinding) { + this.fragmentThemColor = fragmentThemColor; + this.fragmentThemColorBinding = fragmentThemColorBinding; + getInfo(); + } + + //=============================================================================== + //================================Event Listeners================================ + //=============================================================================== + + + public void onClickThemCustom(View v) { + new HelperFragment(new FragmentThemColorCustom()).setReplace(false).load(); + } + + public void onClickThemeDefault(View v) { + setSetting(Theme.DEFAULT, false); + + } + + public void onClickThemeDark(View v) { + new HelperFragment(FragmentDarkTheme.newInstance()).setReplace(false).load(); + + } + + public void onClickThemeRed(View v) { + setSetting(Theme.RED, false); + + } + + public void onClickThemePink(View v) { + setSetting(Theme.PINK, false); + } + + public void onClickThemePurple(View v) { + setSetting(Theme.PURPLE, false); + } + + public void onClickThemeDeepPurple(View v) { + setSetting(Theme.DEEPPURPLE, false); + } + + public void onClickThemeIndigo(View v) { + setSetting(Theme.INDIGO, false); + } + + public void onClickThemeBlue(View v) { + setSetting(Theme.BLUE, false); + } + + public void onClickThemeLightBlue(View v) { + setSetting(Theme.LIGHT_BLUE, false); + } + + public void onClickThemeCyan(View v) { + setSetting(Theme.CYAN, false); + } + + public void onClickThemeTeal(View v) { + setSetting(Theme.TEAL, false); + } + + public void onClickThemeGreen(View v) { + setSetting(Theme.GREEN, false); + } + + public void onClickThemeLightGreen(View v) { + setSetting(Theme.LIGHT_GREEN, false); + } + + public void onClickThemeLime(View v) { + setSetting(Theme.LIME, false); + } + + public void onClickThemeYellow(View v) { + setSetting(Theme.YELLLOW, false); + } + + public void onClickThemeAmber(View v) { + setSetting(Theme.AMBER, false); + ; + } + + public void onClickThemeOrange(View v) { + setSetting(Theme.ORANGE, false); + } + + public void onClickThemeDeepOrange(View v) { + setSetting(Theme.DEEP_ORANGE, false); + } + + public void onClickThemeBrown(View v) { + setSetting(Theme.BROWN, false); + + } + + public void onClickThemeGrey(View v) { + setSetting(Theme.GREY, false); + + } + + public void onClickThemeBlueGrey(View v) { + setSetting(Theme.BLUE_GREY, false); + + } + + public void onClickThemeBlueGreyComplete(View v) { + setSetting(Theme.BLUE_GREY_COMPLETE, false); + + } + + public void onClickThemeIndigoComplete(View v) { + setSetting(Theme.INDIGO_COMPLETE, false); + + } + + public void onClickThemeBrownComplete(View v) { + setSetting(Theme.BROWN_COMPLETE, false); + + } + + public void onClickThemeTealComplete(View v) { + setSetting(Theme.TEAL_COMPLETE, false); + + } + + public void onClickThemeGreyComplete(View v) { + setSetting(Theme.GREY_COMPLETE, false); + + } + + private void setSetting(final int config, final boolean isDark) { + + new MaterialDialog.Builder(G.currentActivity) + .title(R.string.customization) + .positiveText(R.string.ok) + .negativeText(R.string.cansel) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(MaterialDialog dialog, DialogAction which) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putInt(SHP_SETTING.KEY_THEME_COLOR, config); + editor.putBoolean(SHP_SETTING.KEY_THEME_DARK, isDark); + editor.apply(); + Theme.setThemeColor(); + if (dialog.isPromptCheckBoxChecked()) { + editor.putString(SHP_SETTING.KEY_APP_BAR_COLOR, G.appBarColor); + editor.putString(SHP_SETTING.KEY_NOTIFICATION_COLOR, G.notificationColor); + editor.putString(SHP_SETTING.KEY_TOGGLE_BOTTON_COLOR, G.toggleButtonColor); + editor.putString(SHP_SETTING.KEY_SEND_AND_ATTACH_ICON_COLOR, G.attachmentColor); + editor.putString(SHP_SETTING.KEY_FONT_HEADER_COLOR, G.headerTextColor); + editor.putString(SHP_SETTING.KEY_PROGRES_COLOR, G.progressColor); + editor.apply(); + } + resetApp(); + } + }) + .checkBoxPromptRes(R.string.Apply_colors_to_customize, false, null) + .show(); + + } + + public static void resetApp() { + + G.isUpdateNotificaionColorMain = true; + G.isUpdateNotificaionColorChannel = true; + G.isUpdateNotificaionColorGroup = true; + G.isUpdateNotificaionColorChat = true; + G.fragmentActivity.recreate(); + + if (G.onRefreshActivity != null) { + G.isRestartActivity = true; + G.onRefreshActivity.refresh(""); + } + } + + + private void getInfo() { + sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE); + + String appBarColor = sharedPreferences.getString(SHP_SETTING.KEY_APP_BAR_COLOR, Theme.default_appBarColor); + if (fragmentThemColor != null) { + GradientDrawable circleCustomColor = (GradientDrawable) fragmentThemColorBinding.themeCustom1.getBackground(); + circleCustomColor.setColor(Color.parseColor(appBarColor)); + + GradientDrawable circleDefaultColor = (GradientDrawable) fragmentThemColorBinding.themeDefault1.getBackground(); + circleDefaultColor.setColor(Color.parseColor(Theme.default_appBarColor)); + + GradientDrawable circleDarkColor = (GradientDrawable) fragmentThemColorBinding.themeDark1.getBackground(); + circleDarkColor.setColor(Color.parseColor(Theme.default_dark_appBarColor)); + + GradientDrawable circleRedColor = (GradientDrawable) fragmentThemColorBinding.themeRed1.getBackground(); + circleRedColor.setColor(Color.parseColor(Theme.default_red_appBarColor)); + + GradientDrawable circlePinkColor = (GradientDrawable) fragmentThemColorBinding.themePink1.getBackground(); + circlePinkColor.setColor(Color.parseColor(Theme.default_Pink_appBarColor)); + + GradientDrawable circlePurpleColor = (GradientDrawable) fragmentThemColorBinding.themePurple1.getBackground(); + circlePurpleColor.setColor(Color.parseColor(Theme.default_purple_appBarColor)); + + GradientDrawable circleDeepPurpleColor = (GradientDrawable) fragmentThemColorBinding.themeDeepPurple1.getBackground(); + circleDeepPurpleColor.setColor(Color.parseColor(Theme.default_deepPurple_appBarColor)); + + GradientDrawable circleDeepIndigoColor = (GradientDrawable) fragmentThemColorBinding.themeIndigo.getBackground(); + circleDeepIndigoColor.setColor(Color.parseColor(Theme.default_indigo_appBarColor)); + + GradientDrawable circleBlueColor = (GradientDrawable) fragmentThemColorBinding.themeBlue.getBackground(); + circleBlueColor.setColor(Color.parseColor(Theme.default_blue_appBarColor)); + + GradientDrawable circleLightBlueColor = (GradientDrawable) fragmentThemColorBinding.themeLightBlue.getBackground(); + circleLightBlueColor.setColor(Color.parseColor(Theme.default_lightBlue_appBarColor)); + + GradientDrawable circleCyanColor = (GradientDrawable) fragmentThemColorBinding.themeCyan.getBackground(); + circleCyanColor.setColor(Color.parseColor(Theme.default_cyan_appBarColor)); + + GradientDrawable circleTealColor = (GradientDrawable) fragmentThemColorBinding.themeTeal.getBackground(); + circleTealColor.setColor(Color.parseColor(Theme.default_teal_appBarColor)); + + GradientDrawable circleGreenColor = (GradientDrawable) fragmentThemColorBinding.themeGreen.getBackground(); + circleGreenColor.setColor(Color.parseColor(Theme.default_green_appBarColor)); + + GradientDrawable circleLightGreenColor = (GradientDrawable) fragmentThemColorBinding.themeLightGreen.getBackground(); + circleLightGreenColor.setColor(Color.parseColor(Theme.default_lightGreen_appBarColor)); + + GradientDrawable circleLimeColor = (GradientDrawable) fragmentThemColorBinding.themeLime.getBackground(); + circleLimeColor.setColor(Color.parseColor(Theme.default_lime_appBarColor)); + + GradientDrawable circleYellowColor = (GradientDrawable) fragmentThemColorBinding.themeYellow.getBackground(); + circleYellowColor.setColor(Color.parseColor(Theme.default_yellow_appBarColor)); + + GradientDrawable circleAmberColor = (GradientDrawable) fragmentThemColorBinding.themeAmber.getBackground(); + circleAmberColor.setColor(Color.parseColor(Theme.default_amber_appBarColor)); + + GradientDrawable circleOrangeColor = (GradientDrawable) fragmentThemColorBinding.themeOrange.getBackground(); + circleOrangeColor.setColor(Color.parseColor(Theme.default_orange_appBarColor)); + + GradientDrawable circleDeepOrangeColor = (GradientDrawable) fragmentThemColorBinding.themeDeepOrange.getBackground(); + circleDeepOrangeColor.setColor(Color.parseColor(Theme.default_deepOrange_appBarColor)); + + GradientDrawable circleBrownColor = (GradientDrawable) fragmentThemColorBinding.themeBrown.getBackground(); + circleBrownColor.setColor(Color.parseColor(Theme.default_brown_appBarColor)); + + GradientDrawable circleGreyColor = (GradientDrawable) fragmentThemColorBinding.themeGrey.getBackground(); + circleGreyColor.setColor(Color.parseColor(Theme.default_grey_appBarColor)); + + GradientDrawable circleBlueGreyColor = (GradientDrawable) fragmentThemColorBinding.themeBlueGrey.getBackground(); + circleBlueGreyColor.setColor(Color.parseColor(Theme.default_blueGrey_appBarColor)); + + GradientDrawable circleBlueGreyCompleteColor = (GradientDrawable) fragmentThemColorBinding.themeBlueGreyComplete.getBackground(); + circleBlueGreyCompleteColor.setColor(Color.parseColor(Theme.default_blueGrey_appBarColor)); + + GradientDrawable circleIndigoCompleteColor = (GradientDrawable) fragmentThemColorBinding.themeIndigoComplete.getBackground(); + circleIndigoCompleteColor.setColor(Color.parseColor(Theme.default_indigo_appBarColor)); + + GradientDrawable circleBrownCompleteColor = (GradientDrawable) fragmentThemColorBinding.themeBrownComplete.getBackground(); + circleBrownCompleteColor.setColor(Color.parseColor(Theme.default_brown_appBarColor)); + + GradientDrawable circleTealCompleteColor = (GradientDrawable) fragmentThemColorBinding.themeTealComplete.getBackground(); + circleTealCompleteColor.setColor(Color.parseColor(Theme.default_teal_appBarColor)); + + GradientDrawable circleGreyCompleteColor = (GradientDrawable) fragmentThemColorBinding.themeGreyComplete.getBackground(); + circleGreyCompleteColor.setColor(Color.parseColor(Theme.default_grey_appBarColor)); + + + switch (G.themeColor) { + case Theme.CUSTOM: + fragmentThemColorBinding.iconCustom.setVisibility(View.VISIBLE); + break; + case Theme.DEFAULT: + + fragmentThemColorBinding.iconDefault.setVisibility(View.VISIBLE); + break; + case Theme.DARK: + fragmentThemColorBinding.iconDark.setVisibility(View.VISIBLE); + break; + case Theme.RED: + fragmentThemColorBinding.iconRed.setVisibility(View.VISIBLE); + break; + case Theme.PINK: + fragmentThemColorBinding.iconPink.setVisibility(View.VISIBLE); + break; + case Theme.PURPLE: + fragmentThemColorBinding.iconPurple.setVisibility(View.VISIBLE); + break; + case Theme.DEEPPURPLE: + fragmentThemColorBinding.iconDeepPurple.setVisibility(View.VISIBLE); + break; + case Theme.INDIGO: + fragmentThemColorBinding.iconIndigo.setVisibility(View.VISIBLE); + break; + case Theme.BLUE: + fragmentThemColorBinding.iconBlue.setVisibility(View.VISIBLE); + break; + + case Theme.LIGHT_BLUE: + fragmentThemColorBinding.iconLightBlue.setVisibility(View.VISIBLE); + break; + + case Theme.CYAN: + fragmentThemColorBinding.iconCyan.setVisibility(View.VISIBLE); + break; + + case Theme.TEAL: + fragmentThemColorBinding.iconTeal.setVisibility(View.VISIBLE); + break; + + case Theme.GREEN: + fragmentThemColorBinding.iconGreen.setVisibility(View.VISIBLE); + break; + + case Theme.LIGHT_GREEN: + fragmentThemColorBinding.iconLightGreen.setVisibility(View.VISIBLE); + break; + + case Theme.LIME: + fragmentThemColorBinding.iconLime.setVisibility(View.VISIBLE); + break; + + case Theme.YELLLOW: + fragmentThemColorBinding.iconYellow.setVisibility(View.VISIBLE); + break; + case Theme.AMBER: + fragmentThemColorBinding.iconAmber.setVisibility(View.VISIBLE); + break; + + case Theme.ORANGE: + fragmentThemColorBinding.iconOrange.setVisibility(View.VISIBLE); + break; + + case Theme.DEEP_ORANGE: + fragmentThemColorBinding.iconDeepOrange.setVisibility(View.VISIBLE); + break; + + case Theme.BROWN: + fragmentThemColorBinding.iconBrown.setVisibility(View.VISIBLE); + + break; + case Theme.GREY: + + fragmentThemColorBinding.iconGrey.setVisibility(View.VISIBLE); + break; + case Theme.BLUE_GREY: + + fragmentThemColorBinding.iconBlueGrey.setVisibility(View.VISIBLE); + break; + case Theme.BLUE_GREY_COMPLETE: + + fragmentThemColorBinding.iconBlueGreyComplete.setVisibility(View.VISIBLE); + break; + case Theme.INDIGO_COMPLETE: + fragmentThemColorBinding.iconIndigoComplete.setVisibility(View.VISIBLE); + break; + + case Theme.BROWN_COMPLETE: + fragmentThemColorBinding.iconBrownComplete.setVisibility(View.VISIBLE); + break; + case Theme.TEAL_COMPLETE: + fragmentThemColorBinding.iconTealComplete.setVisibility(View.VISIBLE); + break; + + case Theme.GREY_COMPLETE: + fragmentThemColorBinding.iconGreyComplete.setVisibility(View.VISIBLE); + break; + } + + + } + + } +} diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentWalletAgreementViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentWalletAgreementViewModel.java new file mode 100644 index 0000000..f268dd9 --- /dev/null +++ b/app/src/main/java/net/iGap/viewmodel/FragmentWalletAgreementViewModel.java @@ -0,0 +1,77 @@ +package net.iGap.viewmodel; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. +*/ + +import android.content.Intent; +import android.databinding.ObservableField; +import android.support.annotation.NonNull; +import android.view.View; + +import com.afollestad.materialdialogs.DialogAction; +import com.afollestad.materialdialogs.MaterialDialog; + +import net.iGap.G; +import net.iGap.R; +import net.iGap.activities.ActivityMain; +import net.iGap.databinding.FragmentWalletAgrementBinding; +import net.iGap.helper.HelperError; +import net.iGap.request.RequestWalletRegister; + +import org.paygear.wallet.WalletActivity; + +public class FragmentWalletAgreementViewModel { + + + public ObservableField callbackTxtAgreement = new ObservableField<>(G.context.getResources().getString(R.string.loading_wallet_agreement)); + private FragmentWalletAgrementBinding fragmentWalletAgrementBinding; + private String phone; + + public FragmentWalletAgreementViewModel(FragmentWalletAgrementBinding fragmentWalletAgrementBinding, String mPhone) { + this.fragmentWalletAgrementBinding = fragmentWalletAgrementBinding; + phone = mPhone; + } + + public void checkBoxAgreement(View v, boolean checked) { + if (checked) { + new MaterialDialog.Builder(G.fragmentActivity).title(R.string.accept_the_terms). + content(R.string.are_you_sure) + .positiveText(R.string.ok) + .negativeText(R.string.cancel) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + if (G.userLogin) { + new RequestWalletRegister().walletRegister(); + Intent intent = new Intent(G.currentActivity, WalletActivity.class); + intent.putExtra("Language", "fa"); + intent.putExtra("Mobile", "0" + phone); + intent.putExtra("PrimaryColor", G.appBarColor); + intent.putExtra("DarkPrimaryColor", G.appBarColor); + intent.putExtra("AccentColor", G.appBarColor); + intent.putExtra("IS_DARK_THEME", G.isDarkTheme); + intent.putExtra(WalletActivity.PROGRESSBAR, G.progressColor); + intent.putExtra(WalletActivity.LINE_BORDER, G.lineBorder); + intent.putExtra(WalletActivity.BACKGROUND, G.backgroundTheme); + intent.putExtra(WalletActivity.BACKGROUND_2, G.backgroundTheme_2); + intent.putExtra(WalletActivity.TEXT_TITLE, G.textTitleTheme); + intent.putExtra(WalletActivity.TEXT_SUB_TITLE, G.textSubTheme); + (G.currentActivity).startActivity(intent); + + G.fragmentActivity.onBackPressed(); + } else { + HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false); + } + + } + }).show(); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/viewmodel/FragmentWalletViewModel.java b/app/src/main/java/net/iGap/viewmodel/FragmentWalletViewModel.java new file mode 100644 index 0000000..8f6c625 --- /dev/null +++ b/app/src/main/java/net/iGap/viewmodel/FragmentWalletViewModel.java @@ -0,0 +1,20 @@ +package net.iGap.viewmodel; +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. +*/ + +import android.os.Bundle; + + +public class FragmentWalletViewModel { + + public FragmentWalletViewModel(Bundle arguments) { + + } +} \ No newline at end of file diff --git a/app/src/main/java/net/iGap/webrtc/PeerConnectionObserver.java b/app/src/main/java/net/iGap/webrtc/PeerConnectionObserver.java index 668a79d..dcab916 100644 --- a/app/src/main/java/net/iGap/webrtc/PeerConnectionObserver.java +++ b/app/src/main/java/net/iGap/webrtc/PeerConnectionObserver.java @@ -1,12 +1,12 @@ /* -* This is the source code of iGap for Android -* It is licensed under GNU AGPL v3.0 -* You should have received a copy of the license in this archive (see LICENSE). -* Copyright © 2017 , iGap - www.iGap.net -* iGap Messenger | Free, Fast and Secure instant messaging application -* The idea of the RooyeKhat Media Company - www.RooyeKhat.co -* All rights reserved. -*/ + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ //public static ISignalingOffer iSignalingOffer; @@ -31,8 +31,6 @@ import org.webrtc.MediaStream; import org.webrtc.PeerConnection; import org.webrtc.RtpReceiver; -import org.webrtc.VideoRenderer; -import org.webrtc.VideoTrack; import static org.webrtc.PeerConnection.IceConnectionState.CHECKING; import static org.webrtc.PeerConnection.IceConnectionState.CLOSED; @@ -41,8 +39,7 @@ import static org.webrtc.PeerConnection.IceConnectionState.DISCONNECTED; import static org.webrtc.PeerConnection.IceConnectionState.FAILED; -public class PeerConnectionObserver implements PeerConnection.Observer, VideoRenderer.Callbacks { - +public class PeerConnectionObserver implements PeerConnection.Observer { @Override public void onSignalingChange(PeerConnection.SignalingState signalingState) { @@ -94,11 +91,11 @@ public void onAddStream(MediaStream stream) { audioTrack.setEnabled(true); } - if (stream.videoTracks != null && stream.videoTracks.size() == 1) { - VideoTrack videoTrack = stream.videoTracks.getFirst(); + /*if (stream.videoTracks != null && stream.videoTracks.size() == 1) { + VideoTrack videoTrack = stream.videoTracks.get(0); videoTrack.setEnabled(true); videoTrack.addRenderer(new VideoRenderer(this)); - } + }*/ } @Override @@ -121,9 +118,9 @@ public void onAddTrack(RtpReceiver rtpReceiver, MediaStream[] mediaStreams) { } - @Override + /*@Override public void renderFrame(VideoRenderer.I420Frame i420Frame) { Log.i("WWW", "renderFrame : " + i420Frame); - } + }*/ } diff --git a/app/src/main/java/net/iGap/webrtc/WebRTC.java b/app/src/main/java/net/iGap/webrtc/WebRTC.java index 7d26e1e..3c73ca9 100644 --- a/app/src/main/java/net/iGap/webrtc/WebRTC.java +++ b/app/src/main/java/net/iGap/webrtc/WebRTC.java @@ -24,6 +24,7 @@ import org.webrtc.AudioSource; import org.webrtc.AudioTrack; + import org.webrtc.MediaConstraints; import org.webrtc.MediaStream; import org.webrtc.PeerConnection; @@ -51,6 +52,7 @@ public class WebRTC { private AudioTrack audioTrack; private AudioSource audioSource; + public WebRTC() { peerConnectionInstance(); } @@ -90,6 +92,8 @@ private void addAudioTrack(MediaStream mediaStream) { private PeerConnectionFactory peerConnectionFactoryInstance() { if (peerConnectionFactory == null) { + + Set HARDWARE_AEC_WHITELIST = new HashSet() {{ add("D5803"); add("FP1"); @@ -114,12 +118,15 @@ private PeerConnectionFactory peerConnectionFactoryInstance() { } } - PeerConnectionFactory.initializeAndroidGlobals(G.context, // Context - true, // Audio Enabled - false, // Video Enabled - true); // Hardware Acceleration Enabled + //Initialize PeerConnectionFactory globals. + //Params are context, initAudio,initVideo and videoCodecHwAcceleration + //PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true); + PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(G.context).createInitializationOptions()); + - peerConnectionFactory = new PeerConnectionFactory(); + //Create a new PeerConnectionFactory instance. + //PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); + peerConnectionFactory = PeerConnectionFactory.builder().createPeerConnectionFactory(); } return peerConnectionFactory; } diff --git a/app/src/main/java/net/iGap/webservice/APIService.java b/app/src/main/java/net/iGap/webservice/APIService.java new file mode 100644 index 0000000..d4ac72c --- /dev/null +++ b/app/src/main/java/net/iGap/webservice/APIService.java @@ -0,0 +1,28 @@ +package net.iGap.webservice; + +import org.paygear.wallet.model.PaymentResult; + +import okhttp3.RequestBody; +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.Headers; +import retrofit2.http.POST; +import retrofit2.http.Url; + +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ +public interface APIService { + + @POST + Call sendToken(@Url String url, @Body RequestBody JsonBody); + +} diff --git a/app/src/main/java/net/iGap/webservice/ApiUtils.java b/app/src/main/java/net/iGap/webservice/ApiUtils.java new file mode 100644 index 0000000..4ae4110 --- /dev/null +++ b/app/src/main/java/net/iGap/webservice/ApiUtils.java @@ -0,0 +1,24 @@ +package net.iGap.webservice; + +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ +public class ApiUtils { + + private ApiUtils() { + } + + public static final String BASE_URL = "http://test3.igap.net/"; +// public static final String BASE_URL = "https://postman-echo.com/"; + + public static APIService getAPIService() { + + return RetrofitClient.getClient(BASE_URL).create(APIService.class); + } +} diff --git a/app/src/main/java/net/iGap/webservice/Post.java b/app/src/main/java/net/iGap/webservice/Post.java new file mode 100644 index 0000000..f24557e --- /dev/null +++ b/app/src/main/java/net/iGap/webservice/Post.java @@ -0,0 +1,31 @@ +package net.iGap.webservice; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ +public class Post implements Serializable { + + + @SerializedName("body") + @Expose + private String body; + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } +} diff --git a/app/src/main/java/net/iGap/webservice/RetrofitClient.java b/app/src/main/java/net/iGap/webservice/RetrofitClient.java new file mode 100644 index 0000000..add59db --- /dev/null +++ b/app/src/main/java/net/iGap/webservice/RetrofitClient.java @@ -0,0 +1,36 @@ +package net.iGap.webservice; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +/* + * This is the source code of iGap for Android + * It is licensed under GNU AGPL v3.0 + * You should have received a copy of the license in this archive (see LICENSE). + * Copyright © 2017 , iGap - www.iGap.net + * iGap Messenger | Free, Fast and Secure instant messaging application + * The idea of the RooyeKhat Media Company - www.RooyeKhat.co + * All rights reserved. + */ +public class RetrofitClient { + + private static Retrofit retrofit = null; + + public static Retrofit getClient(String baseUrl) { + + if (retrofit == null) { + Gson gson = new GsonBuilder() + .setLenient() + .create(); + retrofit = new Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(GsonConverterFactory.create(gson)) + .build(); + } + return retrofit; + } + +} diff --git a/app/src/main/res/drawable-hdpi/background_call_fragment_dark.xml b/app/src/main/res/drawable-hdpi/background_call_fragment_dark.xml index 6940e31..3947c65 100644 --- a/app/src/main/res/drawable-hdpi/background_call_fragment_dark.xml +++ b/app/src/main/res/drawable-hdpi/background_call_fragment_dark.xml @@ -4,7 +4,7 @@ diff --git a/app/src/main/res/drawable-xxxhdpi/background_call_fragment_blue_grey.xml b/app/src/main/res/drawable-xxxhdpi/background_call_fragment_blue_grey.xml new file mode 100644 index 0000000..15cc635 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/background_call_fragment_blue_grey.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-xxxhdpi/background_call_fragment_brown.xml b/app/src/main/res/drawable-xxxhdpi/background_call_fragment_brown.xml new file mode 100644 index 0000000..2ef876f --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/background_call_fragment_brown.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/background_call_fragment_grey.xml b/app/src/main/res/drawable/background_call_fragment_grey.xml new file mode 100644 index 0000000..717a518 --- /dev/null +++ b/app/src/main/res/drawable/background_call_fragment_grey.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/background_call_fragment_indigo.xml b/app/src/main/res/drawable/background_call_fragment_indigo.xml new file mode 100644 index 0000000..1fd440d --- /dev/null +++ b/app/src/main/res/drawable/background_call_fragment_indigo.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/background_call_fragment_teal.xml b/app/src/main/res/drawable/background_call_fragment_teal.xml new file mode 100644 index 0000000..645c8d9 --- /dev/null +++ b/app/src/main/res/drawable/background_call_fragment_teal.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_circle_shape.xml b/app/src/main/res/drawable/ic_circle_shape.xml new file mode 100644 index 0000000..5acc436 --- /dev/null +++ b/app/src/main/res/drawable/ic_circle_shape.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_direction.xml b/app/src/main/res/drawable/ic_direction.xml new file mode 100644 index 0000000..5f27d08 --- /dev/null +++ b/app/src/main/res/drawable/ic_direction.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_error.xml b/app/src/main/res/drawable/ic_error_igap.xml similarity index 100% rename from app/src/main/res/drawable/ic_error.xml rename to app/src/main/res/drawable/ic_error_igap.xml diff --git a/app/src/main/res/drawable/ic_gps_layer.xml b/app/src/main/res/drawable/ic_gps_layer.xml new file mode 100644 index 0000000..4f47230 --- /dev/null +++ b/app/src/main/res/drawable/ic_gps_layer.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_gps_open_map.xml b/app/src/main/res/drawable/ic_gps_open_map.xml new file mode 100644 index 0000000..9e4b26a --- /dev/null +++ b/app/src/main/res/drawable/ic_gps_open_map.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_location.xml b/app/src/main/res/drawable/ic_location.xml new file mode 100644 index 0000000..d18cdc1 --- /dev/null +++ b/app/src/main/res/drawable/ic_location.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/loading_background.xml b/app/src/main/res/drawable/loading_background.xml new file mode 100644 index 0000000..0d45b2e --- /dev/null +++ b/app/src/main/res/drawable/loading_background.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/oval_gray.xml b/app/src/main/res/drawable/oval_gray.xml index 8c8836a..4a669a9 100644 --- a/app/src/main/res/drawable/oval_gray.xml +++ b/app/src/main/res/drawable/oval_gray.xml @@ -1,11 +1,11 @@ - + - + \ No newline at end of file diff --git a/app/src/main/res/drawable/oval_green.xml b/app/src/main/res/drawable/oval_green.xml index 675a2f7..4f06e3e 100644 --- a/app/src/main/res/drawable/oval_green.xml +++ b/app/src/main/res/drawable/oval_green.xml @@ -1,11 +1,11 @@ - + + android:bottom="2dp" + android:left="2dp" + android:right="2dp" + android:top="2dp" /> \ No newline at end of file diff --git a/app/src/main/res/drawable/rectangle_wallet_bable.xml b/app/src/main/res/drawable/rectangle_wallet_bable.xml new file mode 100644 index 0000000..16bdffb --- /dev/null +++ b/app/src/main/res/drawable/rectangle_wallet_bable.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_chat.xml b/app/src/main/res/layout/activity_chat.xml index b4e5734..beb43a4 100644 --- a/app/src/main/res/layout/activity_chat.xml +++ b/app/src/main/res/layout/activity_chat.xml @@ -680,7 +680,7 @@ android:gravity="center" android:text="@string/md_expand_arrow" android:textAppearance="@style/TextIconAppearance_toolbar" - android:textColor="@color/green" + style="?backgroundColorSettingTheme" android:textSize="@dimen/dp20" /> @@ -704,7 +704,7 @@ android:gravity="center" android:text="@string/md_downwards_arrow" android:textAppearance="@style/TextIconAppearance_toolbar" - android:textColor="@color/green" + style="?backgroundColorSettingTheme" android:textSize="@dimen/dp20" /> diff --git a/app/src/main/res/layout/activity_new_group.xml b/app/src/main/res/layout/activity_new_group.xml index d9ab8db..1c25bda 100644 --- a/app/src/main/res/layout/activity_new_group.xml +++ b/app/src/main/res/layout/activity_new_group.xml @@ -157,7 +157,7 @@ android:id="@+id/ng_view_newGroup" android:layout_width="match_parent" android:layout_height="0.5dp" - android:background="@color/line_edit_text" /> + android:background="@{Color.parseColor(G.lineBorder),default=@color/toolbar_background}" /> @@ -211,7 +211,7 @@ android:padding="@dimen/dp12" android:singleLine="false" android:text="@string/chi_NEXT_STEP" - android:textColor="@color/toolbar_background" + android:textColor="@{Color.parseColor(G.textTitleTheme),default=@color/toolbar_background}" android:textSize="@dimen/dp15" android:textStyle="normal" @@ -230,7 +230,7 @@ android:onClick="@{fragmentNewGroupVieModel::onClickCancel}" android:padding="@dimen/dp12" android:text="@string/B_cancel" - android:textColor="@color/toolbar_background" + android:textColor="@{Color.parseColor(G.textTitleTheme),default=@color/toolbar_background}" android:textSize="@dimen/dp15" android:textStyle="normal" /> diff --git a/app/src/main/res/layout/activity_qr_code_new_device.xml b/app/src/main/res/layout/activity_qr_code_new_device.xml deleted file mode 100644 index dffdb64..0000000 --- a/app/src/main/res/layout/activity_qr_code_new_device.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_register.xml b/app/src/main/res/layout/activity_register.xml index 33aa100..ffd3985 100644 --- a/app/src/main/res/layout/activity_register.xml +++ b/app/src/main/res/layout/activity_register.xml @@ -135,6 +135,7 @@ android:textColor="@color/toolbar_title_register"> + @@ -366,6 +369,7 @@ android:visibility="@{fragmentRegisterViewModel.imgVerifySmsVisibility}" /> @@ -458,12 +462,12 @@ android:visibility="@{fragmentRegisterViewModel.imgVerifyServerVisibility}" /> @@ -471,6 +475,7 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet.xml b/app/src/main/res/layout/bottom_sheet.xml index 29b0256..a487861 100644 --- a/app/src/main/res/layout/bottom_sheet.xml +++ b/app/src/main/res/layout/bottom_sheet.xml @@ -22,7 +22,7 @@ android:id="@+id/rcvContent" android:layout_width="wrap_content" android:layout_height="@dimen/dp100" - style="?backgroundColorSettingTheme" + style="?textColorMenuTheme" android:layout_marginLeft="@dimen/dp6" /> @@ -68,15 +68,15 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/icon_folder" - android:textColor="@color/green" android:textSize="@dimen/dp20" /> @@ -100,16 +100,17 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/icon_music" - android:textColor="@color/green" + android:textSize="@dimen/dp20" /> @@ -133,15 +134,15 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/md_videocam" - android:textColor="@color/green" + android:textSize="@dimen/dp20" /> @@ -164,16 +165,17 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/md_igap_folder_image" - android:textColor="@color/green" + android:textSize="@dimen/dp20" /> @@ -197,17 +199,17 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/md_camera_alt" - android:textColor="@color/green" + android:textSize="@dimen/dp20" /> @@ -240,15 +242,15 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/md_user_account_box" - android:textColor="@color/green" + android:textSize="@dimen/dp20" /> @@ -272,16 +274,17 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/md_room" - android:textColor="@color/green" + android:textSize="@dimen/dp20" /> @@ -304,16 +307,16 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/md_brush" - android:textColor="@color/green" + android:textSize="@dimen/dp20" /> @@ -336,15 +339,15 @@ android:layout_gravity="center_horizontal" android:gravity="center" android:text="@string/md_igap_file" - android:textColor="@color/green" + android:textSize="@dimen/dp20" /> @@ -368,7 +371,6 @@ android:gravity="center" android:paddingTop="2dp" android:text="@string/igap_chevron_double_down" - android:textColor="@color/green" android:textSize="@dimen/dp20" /> diff --git a/app/src/main/res/layout/bottom_sheet_forward.xml b/app/src/main/res/layout/bottom_sheet_forward.xml index b2d8d06..4ac2d86 100644 --- a/app/src/main/res/layout/bottom_sheet_forward.xml +++ b/app/src/main/res/layout/bottom_sheet_forward.xml @@ -22,6 +22,7 @@ + android:hint="@string/send_message_to" /> + style="?textColorMenuTheme" /> diff --git a/app/src/main/res/layout/chat_popup_dialog_custom.xml b/app/src/main/res/layout/chat_popup_dialog_custom.xml index 08cc749..89ab56b 100644 --- a/app/src/main/res/layout/chat_popup_dialog_custom.xml +++ b/app/src/main/res/layout/chat_popup_dialog_custom.xml @@ -1,284 +1,314 @@ + android:layout_height="wrap_content" + android:background="@android:color/transparent" + android:clickable="true" + android:orientation="vertical"> + android:layout_height="wrap_content"> + android:id="@+id/dialog_icon_item1_notification" + android:layout_width="@dimen/dp26" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/md_muted" + android:textAppearance="@style/TextIconAppearance.all" + style="?textSubColorSettingTheme" + android:textSize="@dimen/dp18" + + /> + android:layout_height="wrap_content" + android:text="@string/mute_notification" + android:paddingTop="@dimen/dp8" + android:paddingBottom="@dimen/dp8" + android:paddingLeft="@dimen/dp8" + android:paddingRight="@dimen/dp8" + android:textSize="@dimen/dp14" /> + android:layout_height="wrap_content" + android:visibility="gone"> + android:id="@+id/dialog_icon_item2_notification" + android:layout_width="@dimen/dp26" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/md_muted" + android:textAppearance="@style/TextIconAppearance.all" + style="?textSubColorSettingTheme" + android:textSize="@dimen/dp18" /> + android:layout_height="wrap_content" + android:text="@string/mute_notification" + android:paddingTop="@dimen/dp8" + android:paddingBottom="@dimen/dp8" + android:paddingLeft="@dimen/dp8" + android:paddingRight="@dimen/dp8" + android:textSize="@dimen/dp14" /> + android:layout_height="wrap_content" + android:visibility="gone"> + android:id="@+id/dialog_icon_item3_notification" + android:layout_width="@dimen/dp26" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/md_muted" + android:textAppearance="@style/TextIconAppearance.all" + style="?textSubColorSettingTheme" + android:textSize="@dimen/dp18" /> + android:layout_height="wrap_content" + android:text="@string/mute_notification" + android:paddingTop="@dimen/dp8" + android:paddingBottom="@dimen/dp8" + android:paddingLeft="@dimen/dp8" + android:paddingRight="@dimen/dp8" + android:textSize="@dimen/dp14" /> + android:layout_height="wrap_content" + android:visibility="gone"> + android:id="@+id/dialog_icon_item4_notification" + android:layout_width="@dimen/dp26" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/md_muted" + android:textAppearance="@style/TextIconAppearance.all" + style="?textSubColorSettingTheme" + android:textSize="@dimen/dp18" /> + android:layout_height="wrap_content" + android:text="@string/mute_notification" + android:paddingTop="@dimen/dp8" + android:paddingBottom="@dimen/dp8" + android:paddingLeft="@dimen/dp8" + android:paddingRight="@dimen/dp8" + android:textSize="@dimen/dp14" /> + android:layout_height="wrap_content" + android:visibility="gone"> + android:id="@+id/dialog_icon_item5_notification" + android:layout_width="@dimen/dp26" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/md_muted" + android:textAppearance="@style/TextIconAppearance.all" + style="?textSubColorSettingTheme" + android:textSize="@dimen/dp18" /> + android:layout_height="wrap_content" + android:text="@string/mute_notification" + android:paddingTop="@dimen/dp8" + android:paddingBottom="@dimen/dp8" + android:paddingLeft="@dimen/dp8" + android:paddingRight="@dimen/dp8" + android:textSize="@dimen/dp14" /> + android:layout_height="wrap_content" + android:visibility="gone"> + android:id="@+id/dialog_icon_item6_notification" + android:layout_width="@dimen/dp26" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/md_muted" + android:textAppearance="@style/TextIconAppearance.all" + style="?textSubColorSettingTheme" + android:textSize="@dimen/dp18" /> + android:layout_height="wrap_content" + android:text="@string/mute_notification" + android:paddingTop="@dimen/dp8" + android:paddingBottom="@dimen/dp8" + android:paddingLeft="@dimen/dp8" + android:paddingRight="@dimen/dp8" + android:textSize="@dimen/dp14" /> + android:layout_height="wrap_content" + android:visibility="gone"> + android:id="@+id/dialog_icon_item7_notification" + android:layout_width="@dimen/dp26" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/md_muted" + android:textAppearance="@style/TextIconAppearance.all" + style="?textSubColorSettingTheme" + android:textSize="@dimen/dp18" /> + android:layout_height="wrap_content" + android:text="@string/mute_notification" + android:paddingTop="@dimen/dp8" + android:paddingBottom="@dimen/dp8" + android:paddingLeft="@dimen/dp8" + android:paddingRight="@dimen/dp8" + android:textSize="@dimen/dp14" /> + android:layout_height="wrap_content" + android:visibility="gone"> + android:id="@+id/dialog_icon_item8_notification" + android:layout_width="@dimen/dp26" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/md_muted" + android:textAppearance="@style/TextIconAppearance.all" + style="?textSubColorSettingTheme" + android:textSize="@dimen/dp18" /> + + + + + android:visibility="gone"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_active_sessions.xml b/app/src/main/res/layout/fragment_active_sessions.xml index 3158a6d..a8f5961 100644 --- a/app/src/main/res/layout/fragment_active_sessions.xml +++ b/app/src/main/res/layout/fragment_active_sessions.xml @@ -73,6 +73,7 @@ diff --git a/app/src/main/res/layout/fragment_add_contact.xml b/app/src/main/res/layout/fragment_add_contact.xml index 1f3a0ef..3b7c56d 100644 --- a/app/src/main/res/layout/fragment_add_contact.xml +++ b/app/src/main/res/layout/fragment_add_contact.xml @@ -214,8 +214,7 @@ android:singleLine="true" android:text="+98" android:textSize="@dimen/dp15" - style="?textTitleColorSettingTheme" - /> + style="?textTitleColorSettingTheme" /> + + + + + + @@ -248,7 +248,7 @@ android:layout_marginRight="@dimen/dp20" android:onClick="@{fragmentCreateChannelViewModel::onClickCancel}" android:text="@string/B_cancel" - android:textColor="@color/toolbar_background" + android:textColor="@{Color.parseColor(G.appBarColor),default=@color/toolbar_background}" android:textSize="@dimen/dp15" android:textStyle="bold" /> diff --git a/app/src/main/res/layout/fragment_dark_theme.xml b/app/src/main/res/layout/fragment_dark_theme.xml index a990ce4..0b978f0 100644 --- a/app/src/main/res/layout/fragment_dark_theme.xml +++ b/app/src/main/res/layout/fragment_dark_theme.xml @@ -43,7 +43,7 @@ > - @@ -70,19 +70,39 @@ - + + + + + + + diff --git a/app/src/main/res/layout/fragment_edit_image.xml b/app/src/main/res/layout/fragment_edit_image.xml index ebda006..852243f 100644 --- a/app/src/main/res/layout/fragment_edit_image.xml +++ b/app/src/main/res/layout/fragment_edit_image.xml @@ -1,202 +1,229 @@ + - + android:background="@color/colorEditImageBlack" + android:layoutDirection="ltr" + app:contentInsetLeft="0dp" + app:contentInsetStart="0dp"> - + - + android:layout_height="match_parent" + android:orientation="horizontal"> - - - - - - - - + - - - - - - - - - - - + android:textColor="@color/whit_background" /> + - - - - - - - - + android:textStyle="bold" + android:visibility="visible" /> + android:textSize="@dimen/dp22" + android:visibility="gone" /> - + android:textSize="@dimen/dp22" + android:textStyle="bold" + android:visibility="visible" /> + + - + - - + + + + + + + + + + + + + + - + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_financial_services.xml b/app/src/main/res/layout/fragment_financial_services.xml new file mode 100644 index 0000000..177135c --- /dev/null +++ b/app/src/main/res/layout/fragment_financial_services.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_fragment_security.xml b/app/src/main/res/layout/fragment_fragment_security.xml index 3fb0d57..ae6cce2 100644 --- a/app/src/main/res/layout/fragment_fragment_security.xml +++ b/app/src/main/res/layout/fragment_fragment_security.xml @@ -182,8 +182,7 @@ android:textSize="@dimen/dp14" android:textStyle="normal" android:visibility="visible" - style="?textTitleColorSettingTheme" - /> + style="?textTitleColorSettingTheme" /> + android:visibility="visible" /> @@ -374,7 +372,7 @@ android:gravity="left|start" android:onClick="@{fragmentSecurityViewModel::onClickForgotPassword}" android:text="@string/forgot_password" - android:textColor="@color/green" + android:textColor="@{Color.parseColor(G.appBarColor),default=@color/toolbar_background}" android:textSize="@dimen/dp14" /> @@ -395,7 +393,7 @@ android:layout_marginTop="@dimen/dp32" android:gravity="center" android:text="@string/please_create_hint_for_your_password" - style="?textSecurityColor" + style="?textTitleColorSettingTheme" android:textSize="@dimen/dp16" /> @@ -504,7 +502,7 @@ android:layout_marginTop="@dimen/dp8" android:gravity="center" android:text="@string/confirm_email_text" - style="?textSecurityColor" + style="?textTitleColorSettingTheme" android:textSize="@dimen/dp14" /> @@ -525,7 +523,7 @@ android:layout_marginTop="@dimen/dp32" android:gravity="center" android:text="@string/your_email" - style="?textSecurityColor" + style="?textTitleColorSettingTheme" android:textSize="@dimen/dp16" /> @@ -555,7 +553,7 @@ android:layout_marginTop="@dimen/dp18" android:gravity="left|start" android:text="@string/your_email_desc" - style="?textSecurityColor" + style="?textTitleColorSettingTheme" android:textSize="@dimen/dp14" /> @@ -573,7 +571,7 @@ android:layout_marginTop="@dimen/dp32" android:gravity="center" android:text="@string/please_enter_confirm_code" - style="?textSecurityColor" + style="?textTitleColorSettingTheme" android:textSize="@dimen/dp16" /> @@ -604,7 +602,7 @@ android:layout_marginTop="@dimen/dp8" android:gravity="center" android:text="@string/confirm_email_text" - style="?textSecurityColor" + style="?textTitleColorSettingTheme" android:textSize="@dimen/dp14" /> diff --git a/app/src/main/res/layout/fragment_igap_map.xml b/app/src/main/res/layout/fragment_igap_map.xml index e2024b5..fe7359d 100644 --- a/app/src/main/res/layout/fragment_igap_map.xml +++ b/app/src/main/res/layout/fragment_igap_map.xml @@ -290,6 +290,26 @@ /> + + + @@ -335,7 +355,6 @@ android:gravity="center" android:text="@string/md_igap_chevron_double_up" android:textAppearance="@style/TextIconAppearance.all" - android:textColor="@color/green" android:textSize="@dimen/dp26" android:visibility="visible" /> @@ -352,7 +371,7 @@ android:fadeScrollbars="false" android:overScrollMode="never" android:scrollbarSize="5dp" - android:scrollbarThumbVertical="@color/toolbar_background" + android:scrollbarThumbVertical="@color/gray_6c" android:scrollbars="vertical" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_payment_bill.xml b/app/src/main/res/layout/fragment_payment_bill.xml new file mode 100644 index 0000000..15773a6 --- /dev/null +++ b/app/src/main/res/layout/fragment_payment_bill.xml @@ -0,0 +1,268 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +