Showing
6 changed files
with
88 additions
and
4 deletions
d.json
0 → 100644
This diff is collapsed. Click to expand it.
1 | #-*- coding: utf-8 -*- | 1 | #-*- coding: utf-8 -*- |
2 | -import json | 2 | +from datetime import datetime, timedelta |
3 | +import json | ||
4 | +import re | ||
3 | 5 | ||
6 | +''' | ||
7 | +def dday_calculate(date): | ||
8 | + y_m_d = date.split("-") | ||
9 | + return (datetime.now() - datetime(int(y_m_d[0]), int(y_m_d[1]), int(y_m_d[2]))).days | ||
4 | 10 | ||
5 | -with open('tset.json', 'rt', encoding='utf-8') as json_file: | 11 | + |
12 | +def date_calculate(url): | ||
13 | + dates = re.findall(r'[0-9]{2,4}[.|-][0-9]{1,2}[.|-][0-9]{1,2}|~', url) | ||
14 | + | ||
15 | + for i in range(len(dates)): | ||
16 | + dates[i] = dates[i].replace(".", "-") | ||
17 | + | ||
18 | + # 날짜가 없는 경우 | ||
19 | + if len(dates) == 0: | ||
20 | + return "상시" | ||
21 | + | ||
22 | + # XXX ~ | ||
23 | + if dates[-1] == "~": | ||
24 | + dday = dday_calculate(dates[0]) | ||
25 | + if dday > 0: | ||
26 | + return "진행중" | ||
27 | + else: | ||
28 | + return "준비중" | ||
29 | + | ||
30 | + # ~ XXX and XXX ~ XXX | ||
31 | + if dates[-1] != "~": | ||
32 | + dday = dday_calculate(dates[-1]) | ||
33 | + if dday < 0: | ||
34 | + return "D"+str(dday) | ||
35 | + else: | ||
36 | + return "종료" | ||
37 | + | ||
38 | + # except | ||
39 | + return "상 시" | ||
40 | +''' | ||
41 | + | ||
42 | + | ||
43 | +with open('d.json', 'rt', encoding='utf-8') as json_file: | ||
6 | json_data = json.load(json_file) | 44 | json_data = json.load(json_file) |
7 | 45 | ||
8 | 46 | ||
... | @@ -10,6 +48,11 @@ for js in json_data: | ... | @@ -10,6 +48,11 @@ for js in json_data: |
10 | for key, value in js.items(): | 48 | for key, value in js.items(): |
11 | if type(value) != str and key != 'View': | 49 | if type(value) != str and key != 'View': |
12 | js[key] = str(value) | 50 | js[key] = str(value) |
51 | + if key == "Link" and value[0] == '[': | ||
52 | + js[key] = value[1:-1] | ||
53 | +# if key == "Date": | ||
54 | +# js[key] = date_calculate(value) | ||
55 | + | ||
13 | 56 | ||
14 | with open('result.json', 'w', encoding='utf-8') as make_file: | 57 | with open('result.json', 'w', encoding='utf-8') as make_file: |
15 | make_file.write('[') | 58 | make_file.write('[') |
... | @@ -19,4 +62,3 @@ with open('result.json', 'w', encoding='utf-8') as make_file: | ... | @@ -19,4 +62,3 @@ with open('result.json', 'w', encoding='utf-8') as make_file: |
19 | if i != len(json_data) - 1: | 62 | if i != len(json_data) - 1: |
20 | make_file.write(',') | 63 | make_file.write(',') |
21 | make_file.write(']') | 64 | make_file.write(']') |
22 | - | ... | ... |
result.json
0 → 100644
This diff is collapsed. Click to expand it.
... | @@ -9,7 +9,7 @@ android { | ... | @@ -9,7 +9,7 @@ android { |
9 | buildToolsVersion "29.0.2" | 9 | buildToolsVersion "29.0.2" |
10 | defaultConfig { | 10 | defaultConfig { |
11 | applicationId "com.example.vip" | 11 | applicationId "com.example.vip" |
12 | - minSdkVersion 23 | 12 | + minSdkVersion 26 |
13 | targetSdkVersion 29 | 13 | targetSdkVersion 29 |
14 | versionCode 1 | 14 | versionCode 1 |
15 | versionName "1.0" | 15 | versionName "1.0" | ... | ... |
... | @@ -3,6 +3,7 @@ package com.example.vip | ... | @@ -3,6 +3,7 @@ package com.example.vip |
3 | import android.content.Context | 3 | import android.content.Context |
4 | import android.content.Intent | 4 | import android.content.Intent |
5 | import android.content.SharedPreferences | 5 | import android.content.SharedPreferences |
6 | +import android.util.Log | ||
6 | import android.view.LayoutInflater | 7 | import android.view.LayoutInflater |
7 | import android.view.View | 8 | import android.view.View |
8 | import android.view.ViewGroup | 9 | import android.view.ViewGroup |
... | @@ -10,6 +11,11 @@ import android.widget.Toast | ... | @@ -10,6 +11,11 @@ import android.widget.Toast |
10 | import androidx.recyclerview.widget.RecyclerView | 11 | import androidx.recyclerview.widget.RecyclerView |
11 | import kotlinx.android.synthetic.main.item_policy.view.* | 12 | import kotlinx.android.synthetic.main.item_policy.view.* |
12 | import kotlinx.android.synthetic.main.item_policyfield.view.* | 13 | import kotlinx.android.synthetic.main.item_policyfield.view.* |
14 | +import java.time.LocalDate | ||
15 | +import java.text.ParseException | ||
16 | +import java.text.SimpleDateFormat | ||
17 | +import java.time.format.DateTimeFormatter | ||
18 | + | ||
13 | 19 | ||
14 | class PolicyAdapter(private val items: ArrayList<PolicyItem>) : | 20 | class PolicyAdapter(private val items: ArrayList<PolicyItem>) : |
15 | RecyclerView.Adapter<PolicyAdapter.ViewHolder>() { | 21 | RecyclerView.Adapter<PolicyAdapter.ViewHolder>() { |
... | @@ -43,6 +49,36 @@ class PolicyAdapter(private val items: ArrayList<PolicyItem>) : | ... | @@ -43,6 +49,36 @@ class PolicyAdapter(private val items: ArrayList<PolicyItem>) : |
43 | var sepstr=tempstring!!.split("@") | 49 | var sepstr=tempstring!!.split("@") |
44 | var sepstrset=sepstr.toMutableSet() | 50 | var sepstrset=sepstr.toMutableSet() |
45 | 51 | ||
52 | +/* | ||
53 | + fun dday_calculate(date : String) : Long { | ||
54 | + | ||
55 | + var now = LocalDate.now() | ||
56 | + var Strnow = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) | ||
57 | + var calDateDays : Long = 0.toLong() | ||
58 | + | ||
59 | + try { // String Type을 Date Type으로 캐스팅하면서 생기는 예외로 인해 여기서 예외처리 해주지 않으면 컴파일러에서 에러가 발생해서 컴파일을 할 수 없다. | ||
60 | + val format = SimpleDateFormat("yyyy-mm-dd") | ||
61 | + // date1, date2 두 날짜를 parse()를 통해 Date형으로 변환. | ||
62 | + val Date = format.parse(date) | ||
63 | + val nowDate = format.parse(Strnow) | ||
64 | + | ||
65 | + // Date로 변환된 두 날짜를 계산한 뒤 그 리턴값으로 long type 변수를 초기화 하고 있다. | ||
66 | + // 연산결과 -950400000. long type 으로 return 된다. | ||
67 | + val calDate = nowDate.getTime() - Date.getTime() | ||
68 | + | ||
69 | + // Date.getTime() 은 해당날짜를 기준으로1970년 00:00:00 부터 몇 초가 흘렀는지를 반환해준다. | ||
70 | + // 이제 24*60*60*1000(각 시간값에 따른 차이점) 을 나눠주면 일수가 나온다. | ||
71 | + calDateDays = calDate / (24 * 60 * 60 * 1000) | ||
72 | + } catch (e: ParseException) { | ||
73 | + calDateDays = 0 | ||
74 | + } | ||
75 | + return calDateDays | ||
76 | + } | ||
77 | + | ||
78 | + fun date_calculate(dday : String) { | ||
79 | + val matchResult : Sequence<MatchResult> = Regex.findAll("abcd") | ||
80 | + return | ||
81 | + }*/ | ||
46 | fun bind(item: PolicyItem) { | 82 | fun bind(item: PolicyItem) { |
47 | view.policyImage.setImageDrawable(item.policyItemImage) | 83 | view.policyImage.setImageDrawable(item.policyItemImage) |
48 | if (item.policyItemDate == "") { item.policyItemDate = "상시" } | 84 | if (item.policyItemDate == "") { item.policyItemDate = "상시" } | ... | ... |
... | @@ -60,8 +60,11 @@ | ... | @@ -60,8 +60,11 @@ |
60 | android:layout_width="match_parent" | 60 | android:layout_width="match_parent" |
61 | android:layout_height="10dp" | 61 | android:layout_height="10dp" |
62 | android:layout_marginLeft="14dp" | 62 | android:layout_marginLeft="14dp" |
63 | + android:layout_marginRight="12dp" | ||
63 | android:layout_weight="0.7" | 64 | android:layout_weight="0.7" |
65 | + android:ellipsize="end" | ||
64 | android:gravity="bottom|left|center_vertical" | 66 | android:gravity="bottom|left|center_vertical" |
67 | + android:maxLines="1" | ||
65 | android:text="TextView" | 68 | android:text="TextView" |
66 | android:textColor="#C04A4A4A" | 69 | android:textColor="#C04A4A4A" |
67 | android:textSize="13dp" /> | 70 | android:textSize="13dp" /> |
... | @@ -71,8 +74,11 @@ | ... | @@ -71,8 +74,11 @@ |
71 | android:layout_width="match_parent" | 74 | android:layout_width="match_parent" |
72 | android:layout_height="10dp" | 75 | android:layout_height="10dp" |
73 | android:layout_marginLeft="11dp" | 76 | android:layout_marginLeft="11dp" |
77 | + android:layout_marginRight="10dp" | ||
74 | android:layout_weight="1" | 78 | android:layout_weight="1" |
79 | + android:ellipsize="end" | ||
75 | android:gravity="left|center_vertical" | 80 | android:gravity="left|center_vertical" |
81 | + android:maxLines="1" | ||
76 | android:text="TextView" | 82 | android:text="TextView" |
77 | android:textColor="#000" | 83 | android:textColor="#000" |
78 | android:textSize="18dp" /> | 84 | android:textSize="18dp" /> | ... | ... |
-
Please register or login to post a comment