11package org .zephyrsoft .sdbviewer ;
22
3+ import android .Manifest ;
34import android .annotation .SuppressLint ;
45import android .content .Context ;
56import android .content .Intent ;
67import android .content .SharedPreferences ;
7- import android .graphics . Color ;
8+ import android .content . pm . PackageManager ;
89import android .os .AsyncTask ;
910import android .os .Bundle ;
1011import android .os .Handler ;
1112import android .os .Parcelable ;
1213import android .preference .PreferenceManager ;
13- import androidx .annotation .ColorInt ;
14- import androidx .annotation .NonNull ;
15- import androidx .appcompat .app .AppCompatActivity ;
16- import androidx .recyclerview .widget .LinearLayoutManager ;
17- import androidx .recyclerview .widget .RecyclerView ;
18- import androidx .appcompat .widget .Toolbar ;
1914import android .util .Log ;
2015import android .view .LayoutInflater ;
2116import android .view .Menu ;
2621import android .widget .TextView ;
2722import android .widget .Toast ;
2823
24+ import androidx .activity .result .ActivityResultLauncher ;
25+ import androidx .activity .result .contract .ActivityResultContracts ;
26+ import androidx .annotation .NonNull ;
27+ import androidx .appcompat .app .AppCompatActivity ;
28+ import androidx .appcompat .widget .Toolbar ;
29+ import androidx .core .content .ContextCompat ;
30+ import androidx .recyclerview .widget .LinearLayoutManager ;
31+ import androidx .recyclerview .widget .RecyclerView ;
32+
2933import org .zephyrsoft .sdbviewer .fetch .FetchException ;
3034import org .zephyrsoft .sdbviewer .fetch .SDBFetcher ;
3135import org .zephyrsoft .sdbviewer .model .Song ;
@@ -116,6 +120,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
116120 public boolean onQueryTextSubmit (String query ) {
117121 return handleSearchText (query );
118122 }
123+
119124 @ Override
120125 public boolean onQueryTextChange (String newText ) {
121126 return handleSearchText (newText );
@@ -153,6 +158,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
153158 startActivity (intentSettings );
154159 return true ;
155160
161+ case R .id .action_import_settings :
162+ if (ContextCompat .checkSelfPermission (this , Manifest .permission .CAMERA ) ==
163+ PackageManager .PERMISSION_GRANTED ) {
164+ Intent intentImportSettings = new Intent (this , QRScannerActivity .class );
165+ startActivity (intentImportSettings );
166+ } else {
167+ qrCodeScannerLauncher .launch (Manifest .permission .CAMERA );
168+ }
169+ return true ;
170+
156171 case R .id .action_about :
157172 Intent intentAbout = new Intent (this , AboutActivity .class );
158173 startActivity (intentAbout );
@@ -166,6 +181,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
166181 }
167182 }
168183
184+ private ActivityResultLauncher <String > qrCodeScannerLauncher =
185+ registerForActivityResult (new ActivityResultContracts .RequestPermission (), isGranted -> {
186+ if (isGranted ) {
187+ Intent intentImportSettings = new Intent (this , QRScannerActivity .class );
188+ startActivity (intentImportSettings );
189+ } else {
190+ // TODO explain to the user that the QR scanner is unavailable because the user denied the permission
191+ }
192+ });
193+
194+
169195 private String getUrl () {
170196 SharedPreferences sharedPreferences =
171197 PreferenceManager .getDefaultSharedPreferences (this );
0 commit comments