12
12
13
13
import os
14
14
import functools
15
-
16
15
from jnius import autoclass , cast
17
16
17
+ from shared .storage import CrashReport , Rawlog
18
+ from shared .utils import Paths
19
+ from shared .ui .mobile_about_dialog import MobileAboutDialog
20
+
18
21
# Just import if the os is Android to avoid Android peculiarities
19
22
try :
20
23
from android import activity , mActivity , permissions
26
29
except :
27
30
OPERATING_SYSTEM = None
28
31
29
- from shared .storage import CrashReport , Rawlog
30
- from shared .utils import Paths
31
- from shared .ui .mobile_about_dialog import MobileAboutDialog
32
-
33
32
RAWLOG_TAIL = 256
34
33
35
34
import logging
@@ -44,17 +43,18 @@ def build(self):
44
43
self .title = "Monal Mobile Crash Analyzer"
45
44
46
45
self .report = None
47
- self .currentPart = ""
46
+ self .lastCarouselIndex = - 1
48
47
49
48
logger .debug ("Creating ui elements" )
50
49
self .layout = GridLayout (rows = 2 )
51
50
52
51
# Create actionbar
53
52
self .uiActionBar = Factory .ActionBar (pos_hint = {'top' : 1 })
54
- self .rebuildActionBar ()
55
53
56
54
self .uiCarouselWidget = Carousel (direction = 'right' )
57
- self .uiCarouselWidget .bind (on_touch_move = self .onSlideChanged )
55
+ # use touch_up to make sure carousel movement has finished when invoking our handler
56
+ self .uiCarouselWidget .bind (index = self .onCarouselChanged )
57
+ self .uiCarouselWidget .ignore_perpendicular_swipes = True
58
58
59
59
self .layout .add_widget (self .uiActionBar )
60
60
self .layout .add_widget (self .uiCarouselWidget )
@@ -64,18 +64,25 @@ def build(self):
64
64
activity .bind (on_new_intent = self .on_new_intent )
65
65
permissions .request_permissions ([permissions .Permission .READ_EXTERNAL_STORAGE , permissions .Permission .WRITE_EXTERNAL_STORAGE ])
66
66
67
+ self .rebuildActionBar ()
67
68
return self .layout
68
69
69
70
def quit (self , * args ):
70
71
self .stop ()
71
72
72
- def onSlideChanged (self , * args ):
73
+ def onCarouselChanged (self , * args ):
73
74
if self .report == None :
74
75
return ;
75
- self .currentPart = self .report [self .uiCarouselWidget .index ]["name" ]
76
-
77
- # Rebuild ActionBar with new parameters
78
- self .rebuildActionBar ()
76
+ # rebuild ui if the carousel index changed
77
+ if self .uiCarouselWidget .index != self .lastCarouselIndex :
78
+ logger .info ("Showing report having index '%d' and name '%s'..." % (self .uiCarouselWidget .index , self .report [self .uiCarouselWidget .index ]["name" ]))
79
+
80
+ # save current carousel position used to display actionbar title
81
+ # this will be used to check if we have to reload our actionbar
82
+ self .lastCarouselIndex = self .uiCarouselWidget .index
83
+
84
+ # Rebuild ActionBar with new parameters
85
+ self .rebuildActionBar ()
79
86
80
87
def on_start (self , * args ):
81
88
# Use if the os is Android to avoid Android peculiarities
@@ -193,29 +200,18 @@ def loadFile(self, filename):
193
200
194
201
self .uiCarouselWidget .add_widget (uiTextInput )
195
202
196
- logger .debug ("Showing first report part..." )
197
- self .currentPart = self .report [0 ]["name" ]
198
- self .rebuildActionBar ()
203
+ logger .debug ("Loading completed..." )
199
204
except Exception as ex :
200
205
logger .warn ("Exception loading crash report: %s" % str (ex ))
201
206
self .createPopup ("Exception loading crash report: %s" % str (ex ))
202
207
self .resetUi ()
203
208
return
204
209
205
- def switch_part (self , reportName , * args ):
206
- logger .info ("Showing report part '%s'..." % reportName )
207
- for index in range (len (self .report )):
208
- if self .report [index ]["name" ] == reportName :
209
- self .currentPart = reportName
210
-
211
- # Rebuild ActionBar with new parameters
212
- self .rebuildActionBar ()
213
-
214
- self .uiCarouselWidget .index = index
215
-
210
+ def switch_part (self , index , * args ):
211
+ self .uiCarouselWidget .index = index
212
+
216
213
def rebuildActionBar (self , * args ):
217
214
# Rebuild ActionBar because it's impossible to change it
218
-
219
215
logger .debug ("Rebuilding ActionBar..." )
220
216
221
217
# Delete old ActionBar content
@@ -227,8 +223,8 @@ def rebuildActionBar(self, *args):
227
223
228
224
# If report is open objects are loaded
229
225
if self .report != None :
230
- for report in self .report :
231
- button = Factory .ActionButton (text = report ["name" ], on_press = functools .partial (self .switch_part , report [ "name" ] ))
226
+ for index in range ( len ( self .report )) :
227
+ button = Factory .ActionButton (text = self . report [index ][ "name" ], on_press = functools .partial (self .switch_part , index ))
232
228
self .uiActionGroup .add_widget (button )
233
229
button .texture_update ()
234
230
self .uiActionGroup .dropdown_width = max (self .uiActionGroup .dropdown_width , button .texture_size [0 ]) + 16
@@ -237,13 +233,16 @@ def rebuildActionBar(self, *args):
237
233
self .uiActionGroup .add_widget (Factory .ActionButton (text = 'About' , on_press = MobileAboutDialog ))
238
234
239
235
self .uiActionView .add_widget (self .uiActionGroup )
240
- self .uiActionView .add_widget (Factory .ActionPrevious (title = self .currentPart , with_previous = False , app_icon = Paths .get_art_filepath ("quitIcon.png" ), on_press = self .quit ))
236
+ self .uiActionView .add_widget (Factory .ActionPrevious (title = self .report [ self . uiCarouselWidget . index ][ "name" ] if self . report != None else "" , with_previous = False , app_icon = Paths .get_art_filepath ("quitIcon.png" ), on_press = self .quit ))
241
237
self .uiActionBar .add_widget (self .uiActionView )
238
+
239
+ logger .info ("ActionBar now repopulated..." )
242
240
243
241
def resetUi (self ):
244
242
logger .debug ("Reseting ui..." )
245
243
self .uiCarouselWidget .clear_widgets ()
246
244
self .report = None
245
+ self .lastCarouselIndex = - 1
247
246
self .rebuildActionBar ()
248
247
249
248
def createPopup (self , message ):
0 commit comments