Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyPavlenko committed Sep 19, 2018
1 parent 6892fdd commit e671df6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build.gradle
@@ -1,5 +1,5 @@
def version = '1.2.19'
def versionNum = 59
def version = '1.2.20'
def versionNum = 60
def basic_version = '1.0.0'
def basic_versionNum = 1

Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/ap/transmission/btc/activities/MainActivity.java
Expand Up @@ -225,11 +225,18 @@ public boolean onMenuOpened(int featureId, Menu menu) {

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
prepareMenu(menu.getItem(0).getSubMenu());
prepareMenu(menu);
return true;
}

private void prepareMenu(Menu menu) {
private void prepareMenu(Menu m) {
Menu menu = findMenu(m);

if (menu == null) {
Utils.warn(getClass().getName(), "Main menu not found");
return;
}

if (!bindingHelper.isServiceRunning()) {
menu.getItem(0).setVisible(false); // Add file
menu.getItem(1).setVisible(false); // Add link
Expand All @@ -255,6 +262,21 @@ private void prepareMenu(Menu menu) {
}
}

private Menu findMenu(Menu menu) {
for (int i = 0, size = menu.size(); i < size; i++) {
MenuItem item = menu.getItem(i);

if (item.getItemId() == R.id.add_file) {
return menu;
} else if (item.hasSubMenu()) {
Menu m = findMenu(item.getSubMenu());
if (m != null) return m;
}
}

return null;
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == GRANT_PERM) return;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/ap/transmission/btc/views/TorrentView.java
Expand Up @@ -127,6 +127,8 @@ private void showMenu(View v) {
}
} catch (NoSuchTorrentException ex) {
tor.getFs().reportNoSuchTorrent(ex);
} catch (IllegalStateException ex) {
err(getClass().getName(), ex, "Invalid Torrent or TorrentFs");
}

if (isPaused()) {
Expand Down Expand Up @@ -307,6 +309,8 @@ public boolean onLongClick(View v) {
}
} catch (NoSuchTorrentException ex) {
torrent.getFs().reportNoSuchTorrent(ex);
} catch (IllegalStateException ex) {
err(getClass().getName(), ex, "Invalid Torrent or TorrentFs");
}
}
}
Expand Down Expand Up @@ -503,6 +507,8 @@ public void onCheckedChanged(CompoundButton cb, boolean isChecked) {
TorrentView.this.update();
} catch (NoSuchTorrentException ex) {
torrent.getFs().reportNoSuchTorrent(ex);
} catch (IllegalStateException ex) {
err(getClass().getName(), ex, "Invalid Torrent or TorrentFs");
}
}

Expand Down Expand Up @@ -575,6 +581,8 @@ void update() {
progressColor = setProgress(pb, dnd ? 0 : item.getProgress(false), progressColor);
} catch (NoSuchTorrentException ex) {
torrent.getFs().reportNoSuchTorrent(ex);
} catch (IllegalStateException ex) {
err(getClass().getName(), ex, "Invalid Torrent or TorrentFs");
}
}

Expand Down

0 comments on commit e671df6

Please sign in to comment.