3
3
import android .app .Activity ;
4
4
import android .content .ActivityNotFoundException ;
5
5
import android .content .Intent ;
6
- import android .support .annotation .Nullable ;
7
- import android .support .v7 .app .AppCompatActivity ;
8
6
import android .os .Bundle ;
9
- import android .view .View ;
10
7
import android .widget .Button ;
11
8
import android .widget .TextView ;
12
9
import android .widget .Toast ;
13
-
10
+ import androidx .annotation .Nullable ;
11
+ import androidx .appcompat .app .AppCompatActivity ;
14
12
import jp .studyplus .android .sdk .Studyplus ;
15
13
import 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 ;
17
17
18
18
public class MainActivity extends AppCompatActivity {
19
19
@@ -29,44 +29,31 @@ protected void onCreate(Bundle savedInstanceState) {
29
29
getString (R .string .consumer_secret ));
30
30
31
31
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 ();
41
38
}
42
39
});
43
40
44
41
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 ();
66
53
}
67
- });
54
+ }
55
+ });
68
56
69
- }
70
57
});
71
58
}
72
59
0 commit comments