@@ -52,8 +52,7 @@ public class MainActivity extends AppCompatActivity {
5252 protected void onCreate (Bundle savedInstanceState ) {
5353 super .onCreate (savedInstanceState );
5454
55- if (0 != init_mods ())
56- return ;
55+ init_mods ();
5756 b = MainBinding .inflate (getLayoutInflater ());
5857 init_ui ();
5958 init_system ();
@@ -123,37 +122,41 @@ public boolean onCreateOptionsMenu(Menu menu) {
123122
124123 public boolean onOptionsItemSelected (@ NonNull MenuItem item ) {
125124 switch (item .getItemId ()) {
126- case R .id .action_settings :
127- startActivity (new Intent (this , SettingsActivity .class ));
128- return true ;
125+ case R .id .action_settings :
126+ startActivity (new Intent (this , SettingsActivity .class ));
127+ break ;
129128
130- case R .id .action_play_auto_stop :
131- play_auto_stop ();
132- return true ;
129+ case R .id .action_play_auto_stop :
130+ play_auto_stop ();
131+ break ;
133132
134- case R .id .action_file_menu_show :
135- if (mfile == null ) {
136- mfile = new PopupMenu (this , findViewById (R .id .action_file_menu_show ));
137- mfile .getMenuInflater ().inflate (R .menu .file , mfile .getMenu ());
138- mfile .setOnMenuItemClickListener (this ::file_menu_click );
139- }
140- mfile .show ();
141- return true ;
133+ case R .id .action_file_menu_show :
134+ if (mfile == null ) {
135+ mfile = new PopupMenu (this , findViewById (R .id .action_file_menu_show ));
136+ mfile .getMenuInflater ().inflate (R .menu .file , mfile .getMenu ());
137+ mfile .setOnMenuItemClickListener (this ::file_menu_click );
138+ }
139+ mfile .show ();
140+ break ;
142141
143- case R .id .action_list_menu_show :
144- if (mlist == null ) {
145- mlist = new PopupMenu (this , findViewById (R .id .action_list_menu_show ));
146- mlist .getMenuInflater ().inflate (R .menu .list , mlist .getMenu ());
147- mlist .setOnMenuItemClickListener (this ::list_menu_click );
148- }
149- mlist .show ();
150- return true ;
142+ case R .id .action_list_menu_show :
143+ if (mlist == null ) {
144+ mlist = new PopupMenu (this , findViewById (R .id .action_list_menu_show ));
145+ mlist .getMenuInflater ().inflate (R .menu .list , mlist .getMenu ());
146+ mlist .setOnMenuItemClickListener (this ::list_menu_click );
147+ }
148+ mlist .show ();
149+ break ;
151150
152- case R .id .action_about :
153- startActivity (new Intent (this , AboutActivity .class ));
154- return true ;
151+ case R .id .action_about :
152+ startActivity (new Intent (this , AboutActivity .class ));
153+ break ;
154+
155+ default :
156+ return super .onOptionsItemSelected (item );
155157 }
156- return super .onOptionsItemSelected (item );
158+
159+ return true ;
157160 }
158161
159162 private boolean file_menu_click (MenuItem item ) {
@@ -245,19 +248,27 @@ private boolean list_menu_click(MenuItem item) {
245248 return true ;
246249 }
247250
251+ private PopupMenu mlist_sort ;
252+ private static final int [] mlist_sort_data = {
253+ Phiola .QU_SORT_FILENAME , R .string .mlist_sort_filename ,
254+ Phiola .QU_SORT_FILESIZE , R .string .mlist_sort_filesize ,
255+ Phiola .QU_SORT_FILEDATE , R .string .mlist_sort_filedate ,
256+ Phiola .QU_SORT_RANDOM , R .string .mlist_shuffle ,
257+ Phiola .QU_SORT_TAG_ARTIST , R .string .mlist_sort_tag_artist ,
258+ Phiola .QU_SORT_TAG_DATE , R .string .mlist_sort_tag_date ,
259+ };
248260 private void list_sort_menu_show () {
249- PopupMenu m = new PopupMenu (this , b .list );
250- m .setOnMenuItemClickListener ((item ) -> {
251- queue .current_sort (item .getItemId ());
252- return true ;
253- });
254- m .getMenu ().add (0 , Phiola .QU_SORT_FILENAME , 0 , getString (R .string .mlist_sort_filename ));
255- m .getMenu ().add (0 , Phiola .QU_SORT_FILESIZE , 0 , getString (R .string .mlist_sort_filesize ));
256- m .getMenu ().add (0 , Phiola .QU_SORT_FILEDATE , 0 , getString (R .string .mlist_sort_filedate ));
257- m .getMenu ().add (0 , Phiola .QU_SORT_RANDOM , 0 , getString (R .string .mlist_shuffle ));
258- m .getMenu ().add (0 , Phiola .QU_SORT_TAG_ARTIST , 0 , getString (R .string .mlist_sort_tag_artist ));
259- m .getMenu ().add (0 , Phiola .QU_SORT_TAG_DATE , 0 , getString (R .string .mlist_sort_tag_date ));
260- m .show ();
261+ if (mlist_sort == null ) {
262+ mlist_sort = new PopupMenu (this , b .list );
263+ mlist_sort .setOnMenuItemClickListener ((item ) -> {
264+ queue .current_sort (item .getItemId ());
265+ return true ;
266+ });
267+ for (int i = 0 ; i < mlist_sort_data .length ; i += 2 ) {
268+ mlist_sort .getMenu ().add (0 , mlist_sort_data [i ], 0 , getString (mlist_sort_data [i +1 ]));
269+ }
270+ }
271+ mlist_sort .show ();
261272 }
262273
263274 private boolean item_menu_click (MenuItem item ) {
@@ -274,7 +285,7 @@ private boolean item_menu_click(MenuItem item) {
274285 case R .id .action_file_delete :
275286 fn = queue .visible_url (item_menu_qi );
276287 if (!fn .isEmpty ())
277- file_delete_ask (item_menu_qi , fn );
288+ file_delete_ask (FD_VISIBLE , item_menu_qi , fn );
278289 break ;
279290
280291 case R .id .action_file_move :
@@ -283,6 +294,15 @@ private boolean item_menu_click(MenuItem item) {
283294 file_move (fn , item_menu_qi );
284295 break ;
285296
297+ case R .id .action_file_rename :
298+ fn = queue .visible_url (item_menu_qi );
299+ if (!fn .isEmpty ())
300+ file_rename_ask (fn , item_menu_qi );
301+ break ;
302+
303+ case R .id .action_file_show_info :
304+ file_tags_show_sel (item_menu_qi ); break ;
305+
286306 case R .id .action_list_next_add_sel :
287307 fn = queue .visible_url (item_menu_qi );
288308 if (!fn .isEmpty ())
@@ -355,10 +375,8 @@ private boolean user_ask_record() {
355375 }
356376
357377 /** Initialize core and modules */
358- private int init_mods () {
378+ private void init_mods () {
359379 core = Core .init_once (getApplicationContext ());
360- if (core == null )
361- return -1 ;
362380 core .dbglog (TAG , "init_mods()" );
363381
364382 gui = core .gui ();
@@ -379,7 +397,6 @@ public void on_change(int how, int pos) {
379397 track .observer_add (trk_nfy );
380398 trackctl = new TrackCtl (core , this );
381399 trackctl .connect ();
382- return 0 ;
383400 }
384401
385402 /** Set UI objects and register event handlers */
@@ -671,9 +688,13 @@ private void playlist_menu_show() {
671688 }
672689
673690 private void file_tags_show () { startActivity (new Intent (this , TagsActivity .class )); }
691+ private void file_tags_show_sel (int pos ) {
692+ startActivity (new Intent (this , TagsActivity .class )
693+ .putExtra ("pos" , pos ));
694+ }
674695
675696 /** Delete file and update view */
676- private void file_del (int pos , String fn ) {
697+ private void file_del (int how , int pos , String fn ) {
677698 if (!core .setts .file_del ) {
678699 String e = core .util .trash (core .setts .trash_dir , fn );
679700 if (!e .isEmpty ()) {
@@ -687,21 +708,24 @@ private void file_del(int pos, String fn) {
687708 gui .msg_show (this , "Deleted file" );
688709 }
689710
690- plist_filter_clear ();
691- queue .active_remove (pos );
711+ if (how == FD_ACTIVE )
712+ queue .active_remove (pos );
713+ else
714+ queue .current_remove (pos );
692715 }
693716
694717 private void file_del_cur () {
695718 int pos = queue .active_pos ();
696719 String fn = queue .active_track_url ();
697720 if (fn != null )
698- file_delete_ask (pos , fn );
721+ file_delete_ask (FD_ACTIVE , pos , fn );
699722 }
700723
701- private void file_delete_ask (int pos , String fn ) {
702- AlertDialog .Builder b = new AlertDialog .Builder (this );
703- b .setIcon (android .R .drawable .ic_dialog_alert );
704- b .setTitle ("File Delete" );
724+ private static final int
725+ FD_VISIBLE = 0 ,
726+ FD_ACTIVE = 1 ;
727+
728+ private void file_delete_ask (int how , int pos , String fn ) {
705729 String msg , btn ;
706730 if (core .setts .file_del ) {
707731 msg = String .format ("Delete file from storage: %s ?" , fn );
@@ -710,10 +734,9 @@ private void file_delete_ask(int pos, String fn) {
710734 msg = String .format ("Move file to Trash: %s ?" , fn );
711735 btn = "Trash" ;
712736 }
713- b .setMessage (msg );
714- b .setPositiveButton (btn , (dialog , which ) -> file_del (pos , fn ));
715- b .setNegativeButton ("Cancel" , null );
716- b .show ();
737+ GUI .dlg_question (this , "File Delete" , msg
738+ , btn , "Cancel"
739+ , (dialog , which ) -> file_del (how , pos , fn ));
717740 }
718741
719742 private void file_move (String fn , int pos ) {
@@ -738,6 +761,22 @@ private void file_move_confirmed(String fn, int pos) {
738761 gui .msg_show (this , "Moved file to %s" , gui .cur_path );
739762 }
740763
764+ private void file_rename_ask (String fn , int pos ) {
765+ gui .dlg_edit (this , "Rename file"
766+ , "Specify new name" , Util .path_split3 (fn )[1 ]
767+ , "Rename" , "Cancel"
768+ , (new_text ) -> { file_rename_confirmed (pos , new_text ); }
769+ );
770+ }
771+
772+ private void file_rename_confirmed (int pos , String name ) {
773+ if (!queue .visible_track_rename (pos , name )) {
774+ core .errlog (TAG , "file rename: ERROR" );
775+ return ;
776+ }
777+ gui .msg_show (this , "Renamed file" );
778+ }
779+
741780 private void plist_open_new (String fn ) {
742781 list_new ();
743782
@@ -828,7 +867,8 @@ void list_leave() {
828867 if (gui .view == GUI .V_PLAYLIST ) {
829868 queue .current_filter ("" );
830869 gui .list_filter = b .tfilter .getQuery ().toString ();
831- gui .list_scroll_pos_set (queue .current_index (), pos );
870+ if (gui .list_filter .isEmpty ())
871+ gui .list_scroll_pos_set (queue .current_index (), pos );
832872 } else if (gui .view == GUI .V_LIBRARY ) {
833873 gui .mlib_scroll_pos = pos ;
834874 }
0 commit comments