diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 03d9c98..4b6bf5e 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,6 +1,18 @@ + + + + + + + + + + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4c2bddd..ef20db3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,7 +8,7 @@ - + - - + tools:ignore="ProtectedPermissions" /> - + + @@ -39,11 +38,15 @@ android:theme="@style/Theme.SimpliTend" android:usesCleartextTraffic="true" tools:targetApi="31"> + + android:screenOrientation="portrait" /> - - + diff --git a/app/src/main/java/com/app/simplitend/apputils/BootCompleteReceiver.java b/app/src/main/java/com/app/simplitend/apputils/BootCompleteReceiver.java index e12fd56..68a71a3 100644 --- a/app/src/main/java/com/app/simplitend/apputils/BootCompleteReceiver.java +++ b/app/src/main/java/com/app/simplitend/apputils/BootCompleteReceiver.java @@ -16,6 +16,11 @@ public class BootCompleteReceiver extends BroadcastReceiver { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { + if (!AppUtil.isPatientLoggedIn(context)){ + // no senior is logged in + return; + } + AppUtil.updateSeniorOutOfGeofence(context, false); // starting over the Location updates service again diff --git a/app/src/main/java/com/app/simplitend/welcome/activities/NewUpdateActivity.java b/app/src/main/java/com/app/simplitend/welcome/activities/NewUpdateActivity.java new file mode 100644 index 0000000..142d43b --- /dev/null +++ b/app/src/main/java/com/app/simplitend/welcome/activities/NewUpdateActivity.java @@ -0,0 +1,33 @@ +package com.app.simplitend.welcome.activities; + +import android.os.Bundle; +import android.view.View; + +import androidx.appcompat.app.AppCompatActivity; + +import com.app.simplitend.BuildConfig; +import com.app.simplitend.databinding.ActivityNewUpdateBinding; +import com.app.simplitend.welcome.welcomepatient.mvvm.models.NewUpdate; + +public class NewUpdateActivity extends AppCompatActivity { + + public static final String IS_MANDATORY_UPDATE = "is_mandatory_update"; + + protected ActivityNewUpdateBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = ActivityNewUpdateBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + + boolean isMandatoryUpdate = getIntent().getBooleanExtra(IS_MANDATORY_UPDATE, false); + + if (isMandatoryUpdate){ + binding.skipBtn.setVisibility(View.GONE); + }else{ + binding.skipBtn.setVisibility(View.VISIBLE); + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/register/SplashFragment.java b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/register/SplashFragment.java index 7ab3732..aec0111 100644 --- a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/register/SplashFragment.java +++ b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/register/SplashFragment.java @@ -1,5 +1,6 @@ package com.app.simplitend.welcome.welcomepatient.fragments.register; +import static com.app.simplitend.welcome.activities.NewUpdateActivity.IS_MANDATORY_UPDATE; import static com.app.simplitend.welcome.welcomecg.fragments.CgConnectFragment.CAREGIVER_EMAIL; import static com.app.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.CG_STATUS_KEY; import static com.app.simplitend.welcome.welcomepatient.fragments.register.ReActivateFragment.CG_XID_KEY; @@ -20,6 +21,7 @@ import androidx.fragment.app.Fragment; import androidx.navigation.NavOptions; import androidx.navigation.Navigation; +import com.app.simplitend.BuildConfig; import com.app.simplitend.R; import com.app.simplitend.apputils.AppUtil; import com.app.simplitend.apputils.CaregiverDataCache; @@ -31,17 +33,21 @@ import com.app.simplitend.databinding.SplashFragmentBinding; import com.app.simplitend.patient_dashboard.DashBoardActivity; import com.app.simplitend.patientprofile.PatientProfileAPIService; import com.app.simplitend.patientprofile.ProfileContracts; +import com.app.simplitend.welcome.activities.NewUpdateActivity; import com.app.simplitend.welcome.welcomecg.WelcomeApiService; import com.app.simplitend.welcome.welcomecg.WelcomeContracts; import com.app.simplitend.welcome.welcomecg.fragments.CgAuthActivity; import com.app.simplitend.welcome.welcomecg.mvvm.CareGiverData; import com.app.simplitend.welcome.welcomepatient.mvvm.models.CallResponse; +import com.app.simplitend.welcome.welcomepatient.mvvm.models.NewUpdate; import com.app.simplitend.welcome.welcomepatient.mvvm.models.PatientData; import com.onesignal.OneSignal; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +import retrofit2.http.GET; +import retrofit2.http.Query; public class SplashFragment extends Fragment implements ProfileContracts.ProfileProgressCallback, @@ -56,7 +62,7 @@ public class SplashFragment extends Fragment binding = SplashFragmentBinding.inflate(inflater, container, false); binding.retry.setOnClickListener(v -> { - checkIfAhyUser(); + checkNewUpdates(); }); return binding.getRoot(); @@ -65,7 +71,71 @@ public class SplashFragment extends Fragment @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - checkIfAhyUser(); + checkNewUpdates(); + } + + private void checkNewUpdates() { + binding.retry.setVisibility(View.GONE); + binding.loadAnim.setVisibility(View.VISIBLE); + + NewUpdatesApiService apiService = RetrofitHelper.getRetrofit().create(NewUpdatesApiService.class); + apiService.checkNewUpdates(2) + .enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + if (response.body() != null) { + if (response.code() != 200 || response.body().error_code != 0){ + onFailure(call, new Exception("Response code is " + response.code() + " error code is " + response.body().error_code)); + return; + } + + if (response.body().result == null){ + onFailure(call, new Exception("Received result is null")); + return; + } + + if (BuildConfig.VERSION_CODE < response.body().result.new_version){ + // current version is less than latest version + // update is required + + Intent intent = new Intent(requireActivity(), NewUpdateActivity.class); + + if (BuildConfig.VERSION_CODE < response.body().result.force_update_version) { + // current version is less than forced latest version + // update is mandatory + intent.putExtra(IS_MANDATORY_UPDATE, true); + }else{ + // current version is greater than or equal to force update version + // thus, this update can be skipped + intent.putExtra(IS_MANDATORY_UPDATE, false); + } + + try { + startActivity(intent); + requireActivity().finish(); + } catch (Exception e) { + // do nothing + onFailure(call, e); + } + }else{ + // current version is equal to latest version + // no update is required + checkIfAhyUser(); + } + + } else { + onFailure(call, new Exception("Response body is null")); + } + } + + @Override + public void onFailure(Call> call, Throwable t) { + Toast.makeText(requireContext(), "Couldn't connect.", Toast.LENGTH_SHORT).show(); + + binding.retry.setVisibility(View.VISIBLE); + binding.loadAnim.setVisibility(View.GONE); + } + }); } private void checkIfAhyUser() { @@ -315,4 +385,11 @@ public class SplashFragment extends Fragment binding.retry.setVisibility(View.VISIBLE); binding.loadAnim.setVisibility(View.GONE); } + + // new update api + interface NewUpdatesApiService{ + + @GET("api/auth/get-version-history") + Call> checkNewUpdates(@Query("device") int deviceId); + } } \ No newline at end of file diff --git a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/mvvm/models/NewUpdate.java b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/mvvm/models/NewUpdate.java new file mode 100644 index 0000000..4c17b37 --- /dev/null +++ b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/mvvm/models/NewUpdate.java @@ -0,0 +1,16 @@ +package com.app.simplitend.welcome.welcomepatient.mvvm.models; + +import java.io.Serializable; + +public class NewUpdate implements Serializable { + public int id; + public String version_id; + public String release_date; + public int old_version; + public int new_version; + public int force_update_version; + public int force_update; + public String release_notes; + public String created_at; + public String updated_at; +} diff --git a/app/src/main/res/drawable/img_new_update.png b/app/src/main/res/drawable/img_new_update.png new file mode 100644 index 0000000..0fc4a76 Binary files /dev/null and b/app/src/main/res/drawable/img_new_update.png differ diff --git a/app/src/main/res/layout/activity_new_update.xml b/app/src/main/res/layout/activity_new_update.xml new file mode 100644 index 0000000..c709293 --- /dev/null +++ b/app/src/main/res/layout/activity_new_update.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 974b34a..2ab345e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -487,5 +487,9 @@ Cancel Couldn\'t load chats Couldn\'t load + New update available + Unlock enhanced features and improved performance with our latest app update + Update app + skip \ No newline at end of file