Skip to content

Commit

Permalink
fix: lint and fllow android best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Mar 19, 2024
1 parent 7014f8e commit 23fcdf5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,7 @@ public void onErrorResponse(VolleyError error) {

public void unsetChannel(final Callback callback) {
String channelUrl = this.channelUrl;
if (
channelUrl == null || channelUrl.isEmpty()
) {
if (channelUrl == null || channelUrl.isEmpty()) {
Log.e(TAG, "Channel URL is not set");
final JSObject retError = new JSObject();
retError.put("message", "channelUrl missing");
Expand Down Expand Up @@ -940,9 +938,7 @@ public void onErrorResponse(VolleyError error) {

public void setChannel(final String channel, final Callback callback) {
String channelUrl = this.channelUrl;
if (
channelUrl == null || channelUrl.isEmpty()
) {
if (channelUrl == null || channelUrl.isEmpty()) {
Log.e(TAG, "Channel URL is not set");
final JSObject retError = new JSObject();
retError.put("message", "channelUrl missing");
Expand Down Expand Up @@ -1005,9 +1001,7 @@ public void onErrorResponse(VolleyError error) {

public void getChannel(final Callback callback) {
String channelUrl = this.channelUrl;
if (
channelUrl == null || channelUrl.isEmpty()
) {
if (channelUrl == null || channelUrl.isEmpty()) {
Log.e(TAG, "Channel URL is not set");
final JSObject retError = new JSObject();
retError.put("message", "Channel URL is not set");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
private Boolean autoUpdate = false;
private String updateUrl = "";
private Version currentVersionNative;
private Thread backgroundTask;
private Thread backgroundTask;
private Boolean taskRunning = false;

private Boolean isPreviousMainActivity = true;
Expand Down Expand Up @@ -214,7 +214,8 @@ public void notifyListeners(final String id, final JSObject res) {
this.appReadyTimeout = this.getConfig().getInt("appReadyTimeout", 10000);
this.implementation.timeout =
this.getConfig().getInt("responseTimeout", 20) * 1000;
boolean resetWhenUpdate = this.getConfig().getBoolean("resetWhenUpdate", true);
boolean resetWhenUpdate =
this.getConfig().getBoolean("resetWhenUpdate", true);

if (resetWhenUpdate) {
this.cleanupObsoleteVersions();
Expand All @@ -228,15 +229,14 @@ private void semaphoreWait(Number waitTime) {
try {
// Log.i(CapacitorUpdater.TAG, "semaphoreReady count " + CapacitorUpdaterPlugin.this.semaphoreReady.getCount());
semaphoreReady.awaitAdvanceInterruptibly(
semaphoreReady.getPhase(),
waitTime.longValue(),
TimeUnit.SECONDS
);
semaphoreReady.getPhase(),
waitTime.longValue(),
TimeUnit.SECONDS
);
// Log.i(CapacitorUpdater.TAG, "semaphoreReady await " + res);
Log.i(
CapacitorUpdater.TAG,
"semaphoreReady count " +
semaphoreReady.getPhase()
"semaphoreReady count " + semaphoreReady.getPhase()
);
} catch (InterruptedException e) {
Log.i(CapacitorUpdater.TAG, "semaphoreWait InterruptedException");
Expand All @@ -255,8 +255,7 @@ private void semaphoreDown() {
Log.i(CapacitorUpdater.TAG, "semaphoreDown");
Log.i(
CapacitorUpdater.TAG,
"semaphoreDown count " +
semaphoreReady.getPhase()
"semaphoreDown count " + semaphoreReady.getPhase()
);
semaphoreReady.arriveAndDeregister();
}
Expand Down Expand Up @@ -288,7 +287,10 @@ private void cleanupObsoleteVersions() {
try {
if (
!"".equals(previous.getOriginalString()) &&
!Objects.equals(this.currentVersionNative.getOriginalString(), previous.getOriginalString())
!Objects.equals(
this.currentVersionNative.getOriginalString(),
previous.getOriginalString()
)
) {
Log.i(
CapacitorUpdater.TAG,
Expand Down Expand Up @@ -478,7 +480,7 @@ public void unsetChannel(final PluginCall call) {
} else {
if (
CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() &&
Boolean.TRUE.equals(triggerAutoUpdate)
Boolean.TRUE.equals(triggerAutoUpdate)
) {
Log.i(
CapacitorUpdater.TAG,
Expand Down Expand Up @@ -523,7 +525,7 @@ public void setChannel(final PluginCall call) {
} else {
if (
CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() &&
Boolean.TRUE.equals(triggerAutoUpdate)
Boolean.TRUE.equals(triggerAutoUpdate)
) {
Log.i(
CapacitorUpdater.TAG,
Expand Down Expand Up @@ -837,7 +839,10 @@ public void run() {
CapacitorUpdaterPlugin.this.updateUrl,
res -> {
if (res.has("error")) {
Log.e(CapacitorUpdater.TAG, Objects.requireNonNull(res.getString("error")));
Log.e(
CapacitorUpdater.TAG,
Objects.requireNonNull(res.getString("error"))
);
return;
} else if (res.has("version")) {
String newVersion = res.getString("version");
Expand Down Expand Up @@ -1079,7 +1084,10 @@ private void endBackGroundTaskWithNotif(
Boolean error
) {
if (error) {
Log.i(CapacitorUpdater.TAG, "endBackGroundTaskWithNotif error" + error.toString());
Log.i(
CapacitorUpdater.TAG,
"endBackGroundTaskWithNotif error" + error.toString()
);
this.implementation.sendStats("download_fail", current.getVersionName());
final JSObject ret = new JSObject();
ret.put("version", latestVersionName);
Expand Down Expand Up @@ -1151,7 +1159,7 @@ private Thread backgroundDownload() {

if (
latestVersionName != null &&
!latestVersionName.isEmpty() &&
!latestVersionName.isEmpty() &&
!current.getVersionName().equals(latestVersionName)
) {
final BundleInfo latest =
Expand Down Expand Up @@ -1509,9 +1517,11 @@ private boolean isMainActivity() {
ActivityManager.RecentTaskInfo runningTask = runningTasks
.get(0)
.getTaskInfo();
String className = Objects.requireNonNull(runningTask.baseIntent.getComponent()).getClassName();
assert runningTask.topActivity != null;
String runningActivity = runningTask.topActivity.getClassName();
String className = Objects
.requireNonNull(runningTask.baseIntent.getComponent())
.getClassName();
assert runningTask.topActivity != null;
String runningActivity = runningTask.topActivity.getClassName();
return className.equals(runningActivity);
} catch (NullPointerException e) {
return false;
Expand Down

0 comments on commit 23fcdf5

Please sign in to comment.