33import android .app .Activity ;
44import android .content .ActivityNotFoundException ;
55import android .content .Intent ;
6- import android .support .annotation .Nullable ;
7- import android .support .v7 .app .AppCompatActivity ;
86import android .os .Bundle ;
9- import android .view .View ;
107import android .widget .Button ;
118import android .widget .TextView ;
129import android .widget .Toast ;
13-
10+ import androidx .annotation .Nullable ;
11+ import androidx .appcompat .app .AppCompatActivity ;
1412import jp .studyplus .android .sdk .Studyplus ;
1513import jp .studyplus .android .sdk .record .StudyRecord ;
16- import jp .studyplus .android .sdk .record .StudyRecordBuilder ;
14+ import jp .studyplus .android .sdk .record .StudyRecordAmountTotal ;
15+
16+ import java .util .Locale ;
1717
1818public class MainActivity extends AppCompatActivity {
1919
@@ -29,44 +29,31 @@ protected void onCreate(Bundle savedInstanceState) {
2929 getString (R .string .consumer_secret ));
3030
3131 Button startAuthButton = findViewById (R .id .start_auth );
32- startAuthButton .setOnClickListener (new View .OnClickListener () {
33- @ Override
34- public void onClick (View view ) {
35- try {
36- Studyplus .getInstance ().startAuth (MainActivity .this , REQUEST_CODE_AUTH );
37- } catch (ActivityNotFoundException e ) {
38- e .printStackTrace ();
39- Toast .makeText (MainActivity .this , "Need for Studyplus 2.14.0+" , Toast .LENGTH_LONG ).show ();
40- }
32+ startAuthButton .setOnClickListener (view -> {
33+ try {
34+ Studyplus .getInstance ().startAuth (MainActivity .this , REQUEST_CODE_AUTH );
35+ } catch (ActivityNotFoundException e ) {
36+ e .printStackTrace ();
37+ Toast .makeText (MainActivity .this , "Need for Studyplus 2.14.0+" , Toast .LENGTH_LONG ).show ();
4138 }
4239 });
4340
4441 Button postRecordButton = findViewById (R .id .post_study_record );
45- postRecordButton .setOnClickListener (new View .OnClickListener () {
46- @ Override
47- public void onClick (View view ) {
48- StudyRecord record = new StudyRecordBuilder ()
49- .setComment ("勉強した!!!" )
50- .setAmountTotal (30 )
51- .setDurationSeconds (2 * 60 )
52- .build ();
53- Studyplus .getInstance ().postRecord (MainActivity .this , record ,
54- new Studyplus .Companion .OnPostRecordListener () {
55- @ Override
56- public void onResult (boolean success , Long recordId , Throwable throwable ) {
57- if (success ) {
58- Toast .makeText (MainActivity .this ,
59- String .format ("Post Study Record!! (%d)" , recordId ), Toast .LENGTH_LONG ).show ();
60- } else {
61- Toast .makeText (MainActivity .this , "error!!" , Toast .LENGTH_LONG ).show ();
62- if (throwable != null ) {
63- throwable .printStackTrace ();
64- }
65- }
42+ postRecordButton .setOnClickListener (view -> {
43+ StudyRecord record = new StudyRecord (2 * 60 , new StudyRecordAmountTotal (30 ), "勉強した!!!" );
44+ Studyplus .getInstance ().postRecord (MainActivity .this , record ,
45+ (success , recordId , throwable ) -> {
46+ if (success ) {
47+ Toast .makeText (MainActivity .this ,
48+ String .format (Locale .US , "Post Study Record!! (%d)" , recordId ), Toast .LENGTH_LONG ).show ();
49+ } else {
50+ Toast .makeText (MainActivity .this , "error!!" , Toast .LENGTH_LONG ).show ();
51+ if (throwable != null ) {
52+ throwable .printStackTrace ();
6653 }
67- });
54+ }
55+ });
6856
69- }
7057 });
7158 }
7259
0 commit comments