-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dionysis Karatzas
committed
Jul 23, 2019
1 parent
782e33e
commit 8474417
Showing
4 changed files
with
269 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/src/main/java/eu/dkaratzas/android/inapp/update/sample/FlexibleDefaultSnackbar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2019 Dionysios Karatzas | ||
* | ||
* 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 eu.dkaratzas.android.inapp.update.sample; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import eu.dkaratzas.android.inapp.update.InAppUpdateManager; | ||
import eu.dkaratzas.android.inapp.update.InAppUpdateStatus; | ||
|
||
import static eu.dkaratzas.android.inapp.update.Constants.UpdateMode; | ||
|
||
public class FlexibleDefaultSnackbar extends AppCompatActivity implements InAppUpdateManager.InAppUpdateHandler { | ||
private static final int REQ_CODE_VERSION_UPDATE = 530; | ||
private static final String TAG = "Sample"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
InAppUpdateManager inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE) | ||
.resumeUpdates(true) // Resume the update, if the update was stalled. Default is true | ||
.mode(UpdateMode.FLEXIBLE) | ||
.useCustomNotification(false) //default is false | ||
.snackBarMessage("An update has just been downloaded.") | ||
.snackBarAction("RESTART") | ||
.handler(this); | ||
|
||
inAppUpdateManager.checkForAppUpdate(); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
if (requestCode == REQ_CODE_VERSION_UPDATE) { | ||
if (resultCode != RESULT_OK) { | ||
// If the update is cancelled or fails, | ||
// you can request to start the update again. | ||
Log.d(TAG, "Update flow failed! Result code: " + resultCode); | ||
} | ||
} | ||
|
||
super.onActivityResult(requestCode, resultCode, data); | ||
|
||
} | ||
|
||
// InAppUpdateHandler implementation | ||
|
||
@Override | ||
public void onInAppUpdateError(int code, Throwable error) { | ||
/* | ||
* Called when some error occurred. See Constants class for more details | ||
*/ | ||
Log.d(TAG, "code: " + code, error); | ||
} | ||
|
||
@Override | ||
public void onInAppUpdateStatus(InAppUpdateStatus status) { | ||
/* | ||
* Called when the update status change occurred. See Constants class for more details | ||
*/ | ||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
...rc/main/java/eu/dkaratzas/android/inapp/update/sample/FlexibleWithCustomNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2019 Dionysios Karatzas | ||
* | ||
* 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 eu.dkaratzas.android.inapp.update.sample; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import eu.dkaratzas.android.inapp.update.InAppUpdateManager; | ||
import eu.dkaratzas.android.inapp.update.InAppUpdateStatus; | ||
|
||
import static eu.dkaratzas.android.inapp.update.Constants.UpdateMode; | ||
|
||
public class FlexibleWithCustomNotification extends AppCompatActivity implements InAppUpdateManager.InAppUpdateHandler { | ||
private static final int REQ_CODE_VERSION_UPDATE = 530; | ||
private static final String TAG = "Sample"; | ||
private InAppUpdateManager inAppUpdateManager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE) | ||
.resumeUpdates(true) // Resume the update, if the update was stalled. Default is true | ||
.mode(UpdateMode.FLEXIBLE) | ||
// default is false. If is set to true you, | ||
// have to manage the user confirmation when | ||
// you detect the InstallStatus.DOWNLOADED status, | ||
.useCustomNotification(true) | ||
.handler(this); | ||
|
||
inAppUpdateManager.checkForAppUpdate(); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
if (requestCode == REQ_CODE_VERSION_UPDATE) { | ||
if (resultCode != RESULT_OK) { | ||
// If the update is cancelled or fails, | ||
// you can request to start the update again. | ||
inAppUpdateManager.checkForAppUpdate(); | ||
|
||
Log.d(TAG, "Update flow failed! Result code: " + resultCode); | ||
} | ||
} | ||
|
||
super.onActivityResult(requestCode, resultCode, data); | ||
|
||
} | ||
|
||
// InAppUpdateHandler implementation | ||
|
||
@Override | ||
public void onInAppUpdateError(int code, Throwable error) { | ||
/* | ||
* Called when some error occurred. See Constants class for more details | ||
*/ | ||
Log.d(TAG, "code: " + code, error); | ||
} | ||
|
||
@Override | ||
public void onInAppUpdateStatus(InAppUpdateStatus status) { | ||
/* | ||
* If the update downloaded, ask user confirmation and complete the update | ||
*/ | ||
|
||
if (status.isDownloaded()) { | ||
|
||
new AlertDialog.Builder(this) | ||
.setTitle("InAppUpdate") | ||
.setMessage("An update has just been downloaded.") | ||
.setPositiveButton("Complete", (dialog, which) -> { | ||
// Triggers the completion of the update of the app for the flexible flow. | ||
inAppUpdateManager.completeUpdate(); | ||
}) | ||
.setNegativeButton("Cancel", null) | ||
.show(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
app/src/main/java/eu/dkaratzas/android/inapp/update/sample/Immediate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2019 Dionysios Karatzas | ||
* | ||
* 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 eu.dkaratzas.android.inapp.update.sample; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import eu.dkaratzas.android.inapp.update.InAppUpdateManager; | ||
|
||
import static eu.dkaratzas.android.inapp.update.Constants.UpdateMode; | ||
|
||
public class Immediate extends AppCompatActivity { | ||
private static final int REQ_CODE_VERSION_UPDATE = 530; | ||
private static final String TAG = "Sample"; | ||
private InAppUpdateManager inAppUpdateManager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE) | ||
.resumeUpdates(true) // Resume the update, if the update was stalled. Default is true | ||
.mode(UpdateMode.IMMEDIATE); | ||
|
||
inAppUpdateManager.checkForAppUpdate(); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
if (requestCode == REQ_CODE_VERSION_UPDATE) { | ||
if (resultCode == Activity.RESULT_CANCELED) { | ||
// If the update is cancelled by the user, | ||
// you can request to start the update again. | ||
inAppUpdateManager.checkForAppUpdate(); | ||
|
||
Log.d(TAG, "Update flow failed! Result code: " + resultCode); | ||
} | ||
} | ||
|
||
super.onActivityResult(requestCode, resultCode, data); | ||
|
||
} | ||
|
||
} |